52.8k views
0 votes
Assume that credits is an int variable whose value is 0 or positive. Write an expression whose value is "freshman" or "sophomore" or "junior" or "senior" based on the value of credits. In particular: if the value of credits is less than 30 the expression's value is "freshman"; 30-59 would be a "sophomore", 60-89 would be "junior" and 90 or more would be a "senior".

User Pavindu
by
4.8k points

1 Answer

3 votes

Answer:

Step-by-step explanation:

C++ Code

#include<iostream> //for input and output

using namespace std;

int main()

{

int credit = 10;

if(credit<30){

cout<<"frehsman";

}

else if(credit>=30 && credit<60){

cout<<"sophomore";

} else if(credit>=60 && credit<90){

cout<<"junior";

} else if(credit>=90){

cout<<"senior";

}

return 0;

}

Code Explanation

First declare credits variable and assign the desired value to it. then check credits value by using else if in which by applying its condition, print the appropriate expression.

Output

Case 29:

freshman

Case 59:

sophomore

User RussellH
by
5.2k points