c++中用switch语句编程;输入百分制的一个学生成绩,然后按优.良.中.及格.不及格.等级制,输出对应%

发布网友 发布时间:2022-04-23 15:41

我来回答

5个回答

热心网友 时间:2023-10-08 18:56

#include<stdio.h>
void main()
{
int score,i;
printf("Enter the Student's Score:\n");
scanf("%d",&score);
i= score/10;
switch( i )
{
case 10:
case 9: printf("A\n"); break;
case 8: printf("B\n"); break;
case 7: printf("C\n"); break;
case 6: printf("D\n"); break;
default:printf("E\n");
}
}

另一种:
#include <stdio.h>
void main()
{
char grade;
printf("Enter Grade:\n");
grade=getchar();
switch(grade)
{
case 'A': printf("85~100\n");
case 'B': printf("70~84\n");
case 'C': printf("60~69\n");
case 'D': printf("<60\n");
default : printf("ERROR\n");
}
}

再来一种:
#include"stdio.h"
void main()
{
int score;
printf("enter the student's score:\n");
scanf("%d",&score);
if(score>=90)
printf("A\n");
else
{ if(score>=80)
printf("B\n");
else
{ if(score>=70)
printf("C\n");
else
{ if(score>=60)
printf("D\n");
else
printf("E\n");
}
}
}
}
楼主慢慢学习。。。

热心网友 时间:2023-10-08 18:57

/*标准C++语言:*/
#include<iostream>
using namespace std;
void main()
{
int score,i;
cout<<"Enter the Student's Score:"<<endl;
cin>>score;
i= score/10;
switch( i )
{
case 10:
case 9: cout<<"优"<<endl;break;
case 8: cout<<"良"<<endl; break;
case 7: cout<<"中"<<endl;break;
case 6: cout<<"及格"<<endl;break;
default:cout<<"不及格"<<endl;
}
}

热心网友 时间:2023-10-08 18:57

#include <iostream>
using namespace std;

void main()
{
int s,level;
cout<<"Score:";
cin>>s;
while(s>100||s<0)
cin>>s;
level = s/10;
switch( level )
{
case 10:
case 9: cout<<"\n优.\n"; break;
case 8: cout<<"良.\n"; break;
case 7: cout<<"中.\n"; break;
case 6: cout<<"及格.\n"; break;
default:cout<<"不及格.\n"; break;
}
cout<<endl;
}

热心网友 时间:2023-10-08 18:58

#include <iostream>
using namespace std;

string SortMark(double mark);
void main()
{
double mark = 0.0;
cout << "输入成绩: ";
cin >> mark;
string str = SortMark(mark);
cout << "\n等级:" << str.c_str() << endl;
system("pause");
}

// 不及格0 ~ 59
// 及格 60 ~ 69
// 中 70 ~ 79
// 良 80 ~ 90
// 优 90 ~ 100
string SortMark(double mark)
{
if (mark < 0 || mark > 100)
return "Wrong Mark value!";

int iGrade = int (mark / 10) - 5;
switch (iGrade)
{
case 1:
return "及格";
case 2:
return "中";
case 3:
return "良";
case 4:
case 5:
return "优";
default:
return "不及格";
}
}

热心网友 时间:2023-10-08 18:59

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
unsigned char n;
switch(n%10)
{
case 10:printf("You");break;
case 9:printf("You");break;
case 8:printf("Liang");break;
case 7:printf("Zhong");break;
case 6:printf("JiGe");break;
default:printf("BuJiGe");
}
}

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com