我找不到的编译器错误 [英] Compiler error which I am unable to locate
本文介绍了我找不到的编译器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了无法解决的错误。我已经彻底检查了代码,但没有成功。我究竟做错了什么?参见下面的代码。
I'm getting an error which I am not able to resolve. I've gone through my code thoroughly with no success. What am I doing wrong? See code below.
编译器错误:
In function 'main':
ou1.c:49:1: error: expected 'while' before 'printf'
printf("End of program!\n");
^
我的代码:
#include <stdio.h>
int main(void){
int choice;
float price, sum, SUMusd;
float rate =1;
printf("Your shopping assistant");
do{
printf("1. Set exchange rate in usd (currency rate:%f)\n", rate);
printf("2. Read prices in the foreign currency\n");
printf("3. End\n");
printf("\n");
scanf("%d", &choice);
switch(choice){
case 1:
printf("Give exchange rate: \n");
scanf("%f", &rate);
break;
case 2:
do{
printf("Give price(finsh with < 0)\n");
scanf("%f", &price);
sum =+ price;
}while(price <= 0);
SUMusd = sum*rate;
printf("Sum in foreign currency: %f", sum);
printf("Sum in USD:%f", SUMusd);
break;
default:
printf("Invalid choice\n");
break;
}while(choice != 3);
}
printf("End of program!\n");
return 0;
}
推荐答案
开关的花括号需要在while循环终止之前关闭该语句。
The curly braces of the switch statement need to be closed before the while loop termination.
printf( Invalid choice\n);
休息时间;
}
} while(choice!= 3);
printf(程序结束!\n);
更正的完整代码示例
#include <stdio.h>
int main(void){
int choice;
float price, sum, SUMusd;
float rate =1;
printf("Your shopping assistant");
do{
printf("1. Set exchange rate in usd (currency rate:%f)\n", rate);
printf("2. Read prices in the foreign currency\n");
printf("3. End\n");
printf("\n");
scanf("%d", &choice);
switch(choice){
case 1:
printf("Give exchange rate: \n");
scanf("%f", &rate);
break;
case 2:
do{
printf("Give price(finsh with < 0)\n");
scanf("%f", &price);
sum =+ price;
}while(price <= 0);
SUMusd = sum*rate;
printf("Sum in foreign currency: %f", sum);
printf("Sum in USD:%f", SUMusd);
break;
default:
printf("Invalid choice\n");
break;
}
}while(choice != 3);
printf("End of program!\n");
return 0;
}
这篇关于我找不到的编译器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文