My current code is not registering the switch statement will go straight to defa
ID: 3554613 • Letter: M
Question
My current code is not registering the switch statement will go straight to default . I also had the switch statement set to (badGrades) but that was only registering from enum f. any help will be appreciated
int i;
enum grades
{a,b,c,d,f}badGrades;
badGrades =f;
cout<< "Please Enter the letter grades you think you would receive"<<endl;
cout<<"if too much time spent on favorite hobbies"<<endl;
cout<<"please enter two of the same grade use a space in between"<<endl;
cin>>i;
switch (i)
{
case d:
if(i=='d'||i=='D')
cout<<i<<endl;
break;
case f:
cout<<"Your Grade is an F you will fail"<<endl;
break;
case c:
case b:
cout<<"you have been managing your time wisely"<<endl;
break;
case a:
cout<<"good job at juggling school and your hobbies"<<endl;
default:
cout<<" this is not an actual grade please try again"<<endl;
}
system("pause");
;
return 0;
}
Explanation / Answer
In C++, the switch statement takes an int argument, and you are trying to use it with a char, which you can not do in C++.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.