Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include <iostream> #include <cmath> using namespace std; int main() { int grade

ID: 3783349 • Letter: #

Question

#include <iostream>
#include <cmath>


using namespace std;

int main()
{
int grade, score;
cout << "enter you grade"<< endl;
cout << " 1 = A, 2 = B, 3 = C, 4 = D, 5 = F" << endl;
cin >> grade;
if (score >=90){
cout << "you got an A"<< endl;
}else if ((score <90) && (score >=80){
cout << " you got a B"<< endl;
}else if ((score <80)&& (score >=70)){
cout << " you got a C" << endl;
} else if ((score <70)&&(score >=60)){
cout << "you got a D"<< endl;
}else (score <60){
cout << " you failed"<< endl;
}
grade = score;


switch (grade){
case 1:
cout << "you got a great grade" << endl;
break;
case 2:
cout << " you got an ok grade"<< endl;
break;
case 3:
cout << "you got an average grade" << endl;
break;
case 4:
cout << "not so hot"<< endl;
break;
case 5:
cout << "you failed"<< endl;
break;
default:
cout << "not valid grade"<< endl;


}
return 0;
}

trying to make a program using the switch stament that allows users to input there score and have it output there grade depending on the score

Explanation / Answer

Program:

#include <iostream>
#include <cmath>

using namespace std;
int main()
{
int grade, score;
cout << "enter you score"<< endl; // Here we are entering score
cin >> score; // Here we are taking input score from the user

if (score >=90){
cout << "you got an A"<< endl;
}else if ((score <90) && (score >=80)){
cout << " you got a B"<< endl;
}else if ((score <80)&& (score >=70)){
cout << " you got a C" << endl;
} else if ((score <70)&&(score >=60)){
cout << "you got a D"<< endl;
}else if(score <60){ // Here we are taking if else to checking the condition
cout << " you failed"<< endl;
}
grade = score;
cout << "enter you grade"<< endl; // Here we are entering the grade
cout << " 1 = A, 2 = B, 3 = C, 4 = D, 5 = F" << endl;
cin >> grade; // Here we are taking input grade from the user
switch (grade){
case 1:
cout << "you got a great grade" << endl;
break;
case 2:
cout << " you got an ok grade"<< endl;
break;
case 3:
cout << "you got an average grade" << endl;
break;
case 4:
cout << "not so hot"<< endl;
break;
case 5:
cout << "you failed"<< endl;
break;
default:
cout << "not valid grade"<< endl;

}
return 0;
}

Output:

enter you score 90
you got an A
enter you grade
1 = A, 2 = B, 3 = C, 4 = D, 5 = F

1
you got a great grade