0
Could someone tell me where the fault is?
#include <iostream> using namespace std; int main() { int x,a,b,c,d,e; char place; if(x<60) place =a; else if(x<70) place=b; else if(x<80) place=c; else if(x<90) place=d; else if(x<=100) place=e; cin>>place; switch (place) {case 'a':cout<<"E"<<endl;break; case 'b':cout<<"D"<<endl;break; case 'c':cout<<"C"<<endl;break; case 'd':cout<<"B"<<endl;break; case 'e':cout<<"A"<<endl;break; default :cout<<"error"<<endl;} return 0; }
2 Antworten
+ 2
Try it like this:
#include <iostream>
using namespace std;
int main()
{
int x;
char place;
cin>>x;
if(x<60)
place ='a';
else if(x<70)
place='b';
else if(x<80)
place='c';
else if(x<90)
place='d';
else if(x<=100)
place='e';
switch (place)
{case 'a':cout<<"E"<<endl;break;
case 'b':cout<<"D"<<endl;break;
case 'c':cout<<"C"<<endl;break;
case 'd':cout<<"B"<<endl;break;
case 'e':cout<<"A"<<endl;break;
default :cout<<"error"<<endl;}
return 0;
}
Your input should be a number (x).
And the you can assign only characters to the variable place.
You could remove the complete switch construction if you want to. By putting the cout statements directly in the if and else if statements.
0
It worked in my test