关于do--while不能循环的问题?请大家帮帮忙...
#include <stdio.h>
#include <string.h>
#define N 50
struct students
{
int num;
char name[20];
float sc_a;//成绩1
float sc_b;//成绩2
float sc_c;//成绩3
float ave;//平均分
};
static struct students stu[N];
void input()
{
int i=1;
printf("请输入学员信息:\n");
printf("学号:");
scanf("%d",&stu[i-1].num);
printf("\n姓名:");
fflush(stdin);
gets(stu[i-1].name);
printf("\n三门成绩:");
printf("\n成绩1:");
scanf("%f",&stu[i-1].sc_a);
printf("\n成绩2:");
scanf("%f",&stu[i-1].sc_b);
printf("\n成绩3:");
scanf("%f",&stu[i-1].sc_c);
}
void main()
{
int a=0;
char b;
do
{
input();
a++;
if(a>50)
{
printf("你录入的学员信息超过最大值50个。");
break;
}
printf("是否继续录入?<Y or N>\n");
fflush(stdin);
getchar();
b=getchar();
}while(b=='N'||b=='n');
}
[解决办法]
void main() { int a=0; char b; do { input(); a++; if(a >50) { printf("你录入的学员信息超过最大值50个。"); break; } printf("是否继续录入? <Y or N >\n"); fflush(stdin); b=getchar(); }while(b== 'Y'); }
[解决办法]
没仔细看其他的,先把下面的改了吧
while(b== 'N ' ¦ ¦b== 'n ');
-------------------------------------
while(b!= 'N ' ¦ ¦b!= 'n ');
[解决办法]
#include <stdio.h > #include <string.h > #define N 50 struct students { int num; char name[20]; float sc_a;//成绩1 float sc_b;//成绩2 float sc_c;//成绩3 float ave;//平均分 }; static struct students stu[N]; void input() { int i=1; //这里没改,应该作为static并输入完一个后自增 printf("请输入学员信息:\n"); printf("学号:"); scanf("%d",&stu[i-1].num); printf("\n姓名:"); fflush(stdin); gets(stu[i-1].name); printf("\n三门成绩:"); printf("\n成绩1:"); scanf("%f",&stu[i-1].sc_a); printf("\n成绩2:"); scanf("%f",&stu[i-1].sc_b); printf("\n成绩3:"); scanf("%f",&stu[i-1].sc_c); } int main() { int a=0; char b; do { input(); a++; if(a >50) { printf("你录入的学员信息超过最大值50个。"); break; } printf("是否继续录入? <Y or N >\n"); fflush(stdin); // getchar(); //这句不要 b=getchar(); }while(b== 'Y' || b== 'y');//判断条件出错了 return 0;}
[解决办法]
return 0;
有什么作用啊??
----------------------------------------------------
通常是返回给操作系统的,标识程序是否正常结束。约定俗成的规矩,返回0表示程序正常结束,其
它值就可能是异常结束了。