C语言报错的问题?

2024-11-07 01:35:57
推荐回答(2个)
回答(1):

你的程序错误,是在
cout << “Enter the temperature in Celsius:”;
cout << “Fahrenheit value is:”;中用了中文状态下的双引号。

  1. #include

  2. #include

  3. #include

  4. using namespace std;

  5. int main(int nNumberofArgs, char* pszArgs[])

  6. {

  7. // enter the temperature in Celsius

  8. int celsius;

  9. cout << "Enter the temperature in Celsius:";

  10. cin >> celsius;

  11. // calculate conversion factor for Celsius

  12. // to Fahrenheit

  13. int factor;

  14. factor = 212 - 32;

  15. // use conversion factor to convert Celsius

  16. // into Fahrenheit values

  17. int fahrenheit;

  18. fahrenheit = factor * celsius/100 + 32;

  19. // output the results (followed by a NewLine)

  20. cout << "Fahrenheit value is:";

  21. cout << fahrenheit << endl;

  22. // wait until user is ready before terminating program

  23. // to allow the user to see the program results

  24. system("PAUSE");

  25. return 0;

  26. }

以上程序正确,可以运行。

如果还不行,那就是编译器的问题。建议:用vc2008,c-free或vc2010.微软已停止对vc6.0进行更新了。(开始不习惯很正常,成为高手后会喜欢例如vc2010的)。

回答(2):

#include
#include
int main()
{

int gg(int i);
int i;
while(1){
i=0;
printf(" 1.查看历史日程表\n");
printf(" 2.输入新的日程表\n");
printf(" 3.查看已完成的日程表\n");
printf(" 4.查看未完成的日程表\n");
printf(" 5.退出登录\n");
printf(" 请选择相应序号: ");
scanf("%d",&i);
if(i==5){
break;
}
gg(i);
printf("\n");
printf("\n");
printf("\n");
}
}
int gg(int i){
int aa();
int bb();
int cc();
int dd();

switch(i){
case 1:
aa();break;
case 2:
bb();break;
case 3:
cc();break;
case 4:
dd();break;
}
}
int aa(){
FILE*fp;
int length=1000;
char str[1001];
if((fp=fopen("11s.txt","r"))==NULL){
printf("无文件");
return 0;
}
while(fgets(str,length,fp)!=NULL){
printf("%s",str);}
return 1;

fclose(fp);
}
int bb(){
FILE*fp;
char str[400];
printf("内容如下:\n");
scanf("%s",str);
if((fp=fopen("11s.txt","a+"))==NULL){
printf("文件不存在");
return 0;
}

fputs("\n",fp);
fputs(str,fp);
printf("加入成功");
fclose(fp);
return 1;
}
int cc(){
FILE*fp;
int length=1000;
char str[1001];
printf("内容如下:\n");
if((fp=fopen("11s.txt","r"))==NULL){
printf("无文件");
return 0;
}
while(fgets(str,length,fp)!=NULL){
if(strstr(str,"已完成")!=NULL){
printf("%s",str);
}
}
fclose(fp);
return 1;
}
int dd(){
FILE*fp;
int lenght=1000;
char str[1001];
printf("内容如下:\n");
if((fp=fopen("11s.txt","r"))==NULL){
printf("无文件");
return 0;
}
while(fgets(str,lenght,fp)!=NULL){
if(strstr(str,"未完成")!=NULL){
printf("%s",str);
}
}
fclose(fp);
return 1;
}