214k views
1 vote
3.5 code practice input a grade number (9-12) and print Freshman, Sophomore, junior, senior. if it is not in [9-12] , print not in highschool.​

1 Answer

3 votes

Answer:

#include <iostream>

using namespace std;

int main()

{

int grade_number=-2;

while(grade_number!=0){

cout<<"Enter grade number";

cin >> grade_number;

switch (grade_number)

{

case 9:

cout<<"Freshman"<<endl;

break;

case 10:

cout<<"Sphomore"<<endl;

break;

case 11:

cout<<"Junior"<<endl;

break;

case 12:

cout<<"Senior"<<endl;

break;

default : //Optional

cout<<"Not in highschool"<<endl;

}

}

return 0;

}

Step-by-step explanation:

Take input from user for grade number and run it through a switch statement.

Switch statement takes a variable and perform specific task for predefined different values of that variable.

User Chawki Messaoudi
by
5.5k points