0

我正在尝试制作一个程序来获取学生姓名和他的分数。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;
     }
4

1 回答 1

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;
  }
于 2013-09-16T08:33:45.427 回答