Could someone tell me where the fault is? | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
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; }

14th Oct 2018, 8:53 AM
CHN k
2 ответов
+ 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.
14th Oct 2018, 11:27 AM
Paul
Paul - avatar
0
It worked in my test
14th Oct 2018, 9:48 AM
Raziul Islam
Raziul Islam - avatar