在外面套个循环即可。给你写了个小程序:
#include <stdio.h>int main()
{
int a = 0
while(1)
{
袜简 switch(a)
{
case 0:
printf("come into a\n")
姿好谨 a = 1
break
case 1:
printf("come into b\n")
a = 2
break
default:
printf("come into default\n")
return
}
}
return 0
}
有问题请追问!
祝楼主学迹基业进步!
加了注释,如果不懂,可以再问!尽量帮你弄懂!#include <iostream>
int main()
{
///屏幕输出,祥纤没谨纳提示输入分数
std::cout <<"Enter students' grade:"
///声明并初始化两个变量,分数变量grade,计数变量count
float grade(0.0)
int count(0)
///从标准输入中读取分数值
while(std::cin >>grade)
{
///简单地判断输入的分数合不合法,这竖基里分数小于0和分数大于100视为非法输入
if(grade >100 || grade <0)
{
///提示错误信息
std::cerr <<"illegal input grade\n"
///退出
exit(1)
}
///计数器变量加1
++count
///switch判断分数的等级
switch(int(grade/10))
{
case 10:
case 9:
std::cout <<"学生" <<count <<"的成绩为A等\n"
break
case 8:
std::cout <<"学生" <<count <<"的成绩为B等\n"
break
case 7:
std::cout <<"学生" <<count <<"的成绩为C等\n"
break
case 6:
std::cout <<"学生" <<count <<"的成绩为D等\n"
break
default:
std::cout <<"学生" <<count <<"的成绩为E等\n"
break
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)