152k views
1 vote
Write the C++ if statement that compares the contents of the quanity variable to the number 10. If the quantity variable contains a number that is equal to 10, display the string "Equal". If the quantity variable contains a number that is greater than 10, display the string "Over 10". If the quantity variable contains a number that is less than 10, display the string "Not over 10".

1 Answer

4 votes

Answer:

#include <iostream>

using namespace std;

int main

{

//Declare variable quantity

int quantity;

//Accept value for Quantity

cin>>quantity;

//Compare variable quantity with 10

if(quantity == 10)

{

cout<<"Equal";

}

else if(quantity > 10)

{

cout<<"Over 10";

}

else

{

cout<<"Not over 10";

}

return 0;

}

Step-by-step explanation:

The above is a full c++ Program that does executes the instructions in the question.

Lines that starts with // are comments and they are ignored during program execution.

Variable quantity was declared as integer because the number to be compared with (10), is an integer.

Before comparison, the program must accept input. This was shown with the statement "cin>>quantity;"

For each comparison statement, if it's true, the statement within the curly braces {} will be executed.

Comparison of variable quantity with 10 starts at "if(quantity == 10)"

If quantity equals 10, then "Equal" will be printed (without the quotes)

if(quantity>10) means if quantity is greater than 10 and this will print "Over 10", if it's true (without the quotes)

The last comparison statement

"else {"

This will print "Not over 10" (without the quotes) if the first 2 comparison statements are not true.

User Fabs
by
5.0k points