2015-04-11 4 views
-4

Я должен указать имя, количество акций, цену покупки и текущую цену, а затем рассчитать общую сумму покупки, текущую сумму и прибыль. Затем программа должна вывести имя, общую сумму покупки, текущую сумму и прибыль.Что вызывает это предупреждение об ошибке?

Я получаю сообщение об ошибке или аварии после того, как я ввожу свой вход: (. Нажмите, чтобы увеличить)

Screenshot of error alert

Вот то, что я до сих пор:

#define _CRT_SECURE_NO_WARNINGS 
#include<stdio.h> 
#include<stdlib.h> 

void load(char *name, float *share, float *buyprice, float *currprice) 
{ 
    printf("Enter stock name"); 
    gets(name); 
    printf("Enter share, buyprice, currprice"); 
    scanf("%f %f %f", &*share, &*buyprice, &*currprice); 
} 
void calc(float share, float buyprice, float currprice, float *buytotal, float *currtotal, float *profit) 
{ 
    *buytotal = share * buyprice; 
    *currtotal = share * currprice; 
    *profit = *currtotal - *buytotal; 
} 
void output(char name, float profit, float buytotal, float currtotal) 
{ 
    printf("%s\n", name); 
    printf("buy total %f\n", buytotal); 
    printf("current total %f\n", currtotal); 
    printf("profit %f\n", profit); 

} 

void main() 
{ 
    char name [25]; 
    float share, buyprice, currprice, buytotal, currtotal, profit; 
    load(name, &share, &buyprice, &currprice); 
    calc(share, buyprice, currprice, &buytotal, &currtotal, &profit); 
    output(*name, buytotal, currtotal, profit); 
    fflush(stdin); 
    load(name, &share, &buyprice, &currprice); 
    calc(share, buyprice, currprice, &buytotal, &currtotal, &profit); 
    output(*name, buytotal, currtotal, profit); 
    fflush(stdin); 
    load(name, &share, &buyprice, &currprice); 
    calc(share, buyprice, currprice, &buytotal, &currtotal, &profit); 
    output(*name, buytotal, currtotal, profit); 
    system("pause"); 
} 
+1

Вы продолжаете получать * что * ошибка? Пожалуйста, отредактируйте свой вопрос, чтобы быть как можно точнее. – TRiG

+0

http://postimg.org/image/uayeqr7ot/ – TheEWL

+1

Научитесь использовать отладчик. –

ответ

2

У вас есть несколько ошибок, вы можете попробовать следующее:

void load(char *name, float *share, float *buyprice, float *currprice) 
{ 
    printf("Enter stock name"); 
    gets(name); 
    printf("Enter share, buyprice, currprice"); 
    scanf("%f %f %f", share, buyprice, currprice); // changes: removed &* 
} 
void calc(float share, float buyprice, float currprice, float *buytotal, float *currtotal, float *profit) 
{ 
    *buytotal = share * buyprice; 
    *currtotal = share * currprice; 
    *profit = *currtotal - *buytotal; 
} 
void output(char *name, float profit, float buytotal, float currtotal) // changes: char name to char *name 
{ 
    printf("%s\n", name); 
    printf("buy total %f\n", buytotal); 
    printf("current total %f\n", currtotal); 
    printf("profit %f\n", profit); 
} 

int main(void) //changed to int main(void) 
{ 
    char name [25]; 
    float share, buyprice, currprice, buytotal, currtotal, profit; 
    load(name, &share, &buyprice, &currprice); 
    calc(share, buyprice, currprice, &buytotal, &currtotal, &profit); 
    output(name, buytotal, currtotal, profit); //changed *name to name 
    fflush(stdin); 
    load(name, &share, &buyprice, &currprice); 
    calc(share, buyprice, currprice, &buytotal, &currtotal, &profit); 
    output(name, buytotal, currtotal, profit); //changed *name to name 
    fflush(stdin); 
    load(name, &share, &buyprice, &currprice); 
    calc(share, buyprice, currprice, &buytotal, &currtotal, &profit); 
    output(name, buytotal, currtotal, profit); //changed *name to name 
    return 0; //Added this line 
} 
+1

ЭТО РАБОТАЕТ! можете ли вы рассказать мне, какие изменения вы внесли? – TheEWL

+0

уверен, я обновлю ответ –

+0

проверить комментарии –

Смежные вопросы