%f,它停止并返回0。您应该检查返回值。使用int result=scanf_s(“%f”、&priceoferange)。之后,如果result不是1,则向用户打印一条消息,扫描输入,直到看到换行符(刷新用户键入的行),然后重试。同时停止使用浮动价格。它
%f,它停止并返回0。您应该检查返回值。使用int result=scanf_s(“%f”、&priceoferange)。之后,如果result不是1,则向用户打印一条消息,扫描输入,直到看到换行符(刷新用户键入的行),然后重试。同时停止使用浮动价格。它,c,floating-point,scanf,C,Floating Point,Scanf,%f,它停止并返回0。您应该检查返回值。使用int result=scanf_s(“%f”、&priceoferange)。之后,如果result不是1,则向用户打印一条消息,扫描输入,直到看到换行符(刷新用户键入的行),然后重试。同时停止使用浮动价格。它不仅会受到$1.1的影响,而且无法存储$123456789这样的值,因为它只有~7位精度(假设IEEE-754)注释不用于扩展讨论;此对话已结束。评论不用于扩展讨论;这段对话已经结束。 if(priceoforange == .){
%f
,它停止并返回0。您应该检查返回值。使用int result=scanf_s(“%f”、&priceoferange)代码>。之后,如果result
不是1,则向用户打印一条消息,扫描输入,直到看到换行符(刷新用户键入的行),然后重试。同时停止使用浮动价格。它不仅会受到$1.1的影响,而且无法存储$123456789这样的值,因为它只有~7位精度(假设IEEE-754)注释不用于扩展讨论;此对话已结束。评论不用于扩展讨论;这段对话已经结束。
if(priceoforange == .){
printf("Failure);
}
float priceoforange;
printf("\nWhat would you like the cost of orange to be? %c", ch);
scanf_s(" %f", &priceoforange);
#include<stdio.h>
int main()
{
float priceoforange, priceofapple, priceofpear, budget;
int choice; //Customer choses what item he wants to buy
char ch = 156;
printf("--------|Shop Owner Section|--------\n");
printf("Current items in shop are 1-orange, 2-apple and 3-pear\n");
printf("\nWhat would you like the cost of orange to be? %c", ch);
scanf_s(" %f", &priceoforange); //sets the cost of orange to input
printf("What would you like the cost of apple to be? %c", ch);
scanf_s(" %f", &priceofapple);
printf("What would you like the cost of pear to be? %c", ch);
scanf_s(" %f", &priceofpear);
printf("-----|End of Shop Owner Section|----\n");
printf("\nWelcome to the fruit shop\n");
printf("\n------|Shop Menu|------\n");
printf("Item prefixes- cost\n1- Orange %c%.2f\n2- Apple %c%.2f\n3- Pear %c%.2f\n", ch, priceoforange, ch, priceofapple, ch, priceofpear);
printf("\nHello, how much would you like to spend today?\n%c", ch);
scanf_s(" %f", &budget);
printf("\nYour budget for today is %c%.2f\n", ch, budget);
printf("What would you like to buy please select 1 , 2 or 3 from shop menu\n");
scanf_s(" %d", &choice);
if ((choice == 1) && (priceoforange <= budget)){
printf("Success you have purchased orange for %c%.2f", ch, priceoforange);
return(0);
}
else if((choice == 2) && (priceofapple <= budget)){
printf("Success you have purchased Apple for %c%.2f", ch, priceofapple);
return(0);
}
else if ((choice == 3) && (priceofpear <= budget)){
printf("Success you have purchased Pear for %c%.2f", ch, priceofpear);
return(0);
}
else if ((choice < 4) && (priceoforange || priceofapple || priceofpear > budget)) {
printf("\n*****-|Failure you cant make the purchase you have %c%.2f|-*****\n\n", ch, budget);
return(0);
}
else {
printf("\n***** -|Failure you have inputted incorrect information|- *****\n\n");
}
return(0);
}