89.3k views
0 votes
2.Write an if /else if statement that carries out the following logic. If the value of variable quantityOnHand is equal to 0, display the message ''Out of stock''. If the value is greater than 0, but less than 10, display the message ''Reorder ''. If the value is 10 or more do not display anything.

User Emccracken
by
3.3k points

1 Answer

2 votes

Answer:

if(quantityOnHand == 0) { cout<<"Out of stock"; }

else if(quantityOnHand > 0 && quantityOnHand <10) { cout<<"Reorder "; }

else if(quantityOnHand >= 10){ }

See Explanation for comments

Step-by-step explanation:

//This program segment is written in C++

//Only required segment is written

// Comments are used for explanatory purpose

// Program Segment starts here

/*

The following condition tests if quantityOnHand equals 0

If this condition is true, the program prints "Out of stock" without the quotes

*/

if(quantityOnHand == 0) { cout<<"Out of stock"; }

/*

The following condition tests if quantityOnHand is greater than 0, but less than 10

If this condition is true, the program prints "Reorder " without the quotes

*/

else if(quantityOnHand > 0 && quantityOnHand <10) { cout<<"Reorder "; }

/*

The following condition tests if quantityOnHand is greater than o equal to 10

If this condition is true, nothing is done

*/

else if(quantityOnHand >= 10){ }

// End of program segment

Assumption: The program assumes that variable quantityOnHand has already been declared

User Sheikh Rahman
by
3.7k points