我正在尝试制作一个获得学生姓名和成绩的计划。 e。当“退出”是类型时我有退出的功能,我想用名称粘贴结果,例如说: lucius F等。
我解决了最重要的部分,但我没有退出,数据更难。
#include <conio.h>
#include <stdio.h>
int main()
{
int grade;
char name;
looperdo:
printf("\n \nenter student name :");
scanf("%s",& name);
printf(" enter estudent score:");
scanf("%d",&grade);
if(grade>=0 && grade <=49)
printf("grade=F ");
else
if(grade>=50&& grade <=59)
printf(" grade=P ");
if(grade >=60 && grade<=69)
printf(" grade=C");
else
if(grade >=70 && grade <=79)
printf(" grade=D ");
if(grade >=80 && grade<=100)
printf(" grade=HD ,");
if (grade >100 || grade <0)
printf ("out of range , type form 0 to 100.");
goto looperdo;
return 0;
}
答案 0 :(得分:0)
请勿使用goto
执行while
循环:
#include <stdio.h>
#include <string.h>
int main()
{
int grade;
char name[128];
do{
printf("\n \nenter student name :");
scanf("%s",&name);
if(strcmp(name,"quit") == 0){break;} // This part is if you want to quit as soon as quit was printed
printf(" enter estudent score:");
scanf("%d",&grade);
printf("%s - ", name);//This prints the student's name
if(grade>=0 && grade <=49)
printf("grade=F ");
else
if(grade>=50&& grade <=59)
printf(" grade=P ");
if(grade >=60 && grade<=69)
printf(" grade=C");
else
if(grade >=70 && grade <=79)
printf(" grade=D ");
if(grade >=80 && grade<=100)
printf(" grade=HD ,");
if (grade >100 || grade <0)
printf ("out of range , type form 0 to 100.");
}while(name != "quit");
return 0;
}