68.3k views
5 votes
. Write an if/else statement that assign "Excellent" to variable comments (a string data type) when score is 90 or higher, "Good" when score is between 80 and 89, and "Try Harder" when score is less than 80.

1 Answer

1 vote

Answer:

Following are the program in c++

if(score>= 90)

// check if score 90 or higher

{

comments = "Excellent"; // initialize comments to excellent

}

else if(score<90 && score >= 80)

// check if when score is between 80 and 89

{

comments = "Good"; //initialize comments to good

}

else

//when score is less than 80.

{

comments = "Try Harder"; //initialize comments to try harder

}

Explanation:

Following are the program in c++ language

#include<iostream> // header file

using namespace std; // namespace

int main() // main function

{

string comments; // variable

int score; // variable declaration

cout<<" enter score ";

cin>>score;

if(score>= 90)

{

comments = "Excellent"; // initialize comments to execellent

}

else if(score<90 && score >= 80)

{

comments = "Good"; //initialize comments to good

}

else

{

comments = "Try Harder"; //initialize comments to try harder

}

cout<<comments;

return(0);

}

Output:

enter score

45

Try Harder

In this we check the condition

if score>= 90 then it store the Excellent in variable comments of type string

if(score<90 && score >= 80)

it store the Good in variable comments of type string.

otherwise it store harder in variable comments of type string.

User Prince Agrawal
by
6.0k points