Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem 2. Write one or more C++ or NXC statements to perform the following task

ID: 3925616 • Letter: P

Question

Problem 2. Write one or more C++ or NXC statements to perform the following tasks.

(1) Write a C++ statement that prints the message “The number is invalid.” if the variable hours is outside the range 0 through 80.

(2) Write C++ statements 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.

Explanation / Answer

Question 1:

range.cpp

#include <iostream>

using namespace std;

int main()
{
int hours;
cout<<"Enter the number of hours: ";
cin >> hours ;
if(hours <0 || hours > 80){
cout << "The number is invalid." << endl;
}
return 0;
}

Output:

sh-4.3$ g++ -std=c++11 -o main *.cpp                                                                                                                                                                                            

sh-4.3$ main                                                                                                                                                                                                                    

Enter the number of hours: 90                                                                                                                                                                                                   

The number is invalid.

Question 2:

#include <iostream>

using namespace std;

int main()
{
int quantityOnHand ;
cout<<"Enter the number of quantity on hand : ";
cin >>quantityOnHand;
if(quantityOnHand == 0){
cout << "Out of Stock" << endl;
}
else if(quantityOnHand>0 && quantityOnHand<10){
cout<<"Reorder"<<endl;
}
  
return 0;
}

Output:

sh-4.3$ g++ -std=c++11 -o main *.cpp                                                                                                                                                                                            

sh-4.3$ main                                                                                                                                                                                                                    

Enter the number of quantity on hand : 0                                                                                                                                                                                        

Out of Stock                                                                                                                                                                                                                    

sh-4.3$ main                                                                                                                                                                                                                    

Enter the number of quantity on hand : 5                                                                                                                                                                                        

Reorder                                                                                                                                                                                                                         

sh-4.3$ main                                                                                                                                                                                                                    

Enter the number of quantity on hand : 11   

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote