[英]Error conflicting types for function calculatePrice
我編寫了此編碼,然后說“ calculatePrice”的[Error]沖突類型存在錯誤。 我不知道為什么它似乎是一個錯誤。 誰能幫我糾正此錯誤? :((
void Add(struct data* m[])//, struct data* s)
{
char cust, choice1, choice2;
int i, counter = 0;
double totPrice = 0.00;
do
{
printf("Member(M) / Student(S) / Regular Customer(R)?");
scanf("%c", &cust);
printf("Enter name: ");
scanf("%s", &m[counter]->Mname);
printf("Enter phone number : ");
scanf("%s", &m[counter]->MphoneNum);
printf("Enter id : ");
scanf("%s", &m[counter]->Mid);
printf("Enter address");
scanf("%s", &m[counter]->Maddress);
printf("Enter e-mail : ");
scanf("%s", &m[counter]->mail);
do
{
/* totPrice +=*/ calculatePrice(cust);
printf("Wanna add another order?");
scanf("%s", choice1);
}
while(choice1 == 'Y');
counter++;
m[counter]->payment = totPrice;
printf("Wanna add another customer?");
scanf("%s", choice2);
}
while(choice2 == 'Y');
}
double calculatePrice(char cust)
{
char code[4], size, top;
double discount, drPrice, topPrice, price;
if(cust == 'M')
//searchMember(&m, &s);
discount = 0.8;
else if(cust == 'S')
discount = 0.85;
else if(cust == 'R')
discount = 0.0;
printf("Enter the order's code :");
scanf("%s", code);
printf("Enter size of cup : ");
scanf("%s", size);
printf("Enter topping : ");
scanf("%s", top);
if((strcmp(code, "T1")) || (strcmp(code, "T2")) || (strcmp(code, "T3")) ||(strcmp(code, "T4")) || (strcmp(code, "T5")) == 0)
{
if(size == 'R')
drPrice = 4.90;
else
drPrice = 5.90;
}
else if((strcmp(code, "CH1")) || (strcmp(code, "CH2")) || (strcmp(code, "CH3")) || (strcmp(code, "CH4")) || (strcmp(code, "CH5")) == 0)
{
if(size == 'R')
drPrice = 6.90;
else
drPrice = 7.90;
}
else if((strcmp(code, "C2")) || (strcmp(code, "C3")) || (strcmp(code, "C5")) == 0)
drPrice = 5.90;
else if((strcmp(code, "S1")) || (strcmp(code, "S2")) || (strcmp(code, "S5")) || (strcmp(code, "S7")) || (strcmp(code, "S9")) == 0)
drPrice = 6.90;
else if((strcmp(code, "S3")) || (strcmp(code, "S4")) || (strcmp(code, "S6")) || (strcmp(code, "S8")) || (strcmp(code, "S10")) || (strcmp(code, "S11")) == 0)
drPrice = 5.90; //check harga balik
else if((strcmp(code, "C1")) == 0)
drPrice = 3.90;
else if((strcmp(code, "C4")) == 0)
drPrice = 4.90;
if(top == 'B' || top == 'G' || top == 'J' || top == 'P' || top == 'A')
topPrice = 0.60;
else if(top == 'X')
topPrice = 0.00;
price = discount * (topPrice + drPrice);
return price; //return value
}
在該函數中, calculatePrice
printf("Enter size of cup : ");
scanf("%s", size);
printf("Enter topping : ");
scanf("%s", top);
要求輸入字符串,但是目標類型是char
。
應該
printf("Enter size of cup : ");
scanf(" %c", &size);
printf("Enter topping : ");
scanf(" %c", &top);
請注意%c
之前的空格,它將清除上一個輸入之后剩余的空白。
另外請注意, char code[4]
只能接受3個字符。 由於您不限制輸入長度,因此這是一種危險的處理方式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.