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

Write a C++ program that performs the following task. A user is to be prompted f

ID: 642550 • Letter: W

Question

Write a C++ program that performs the following task. A user is to be prompted for an integer value sum that is supposed to be in the interval 0 . . 99.   If the value of sum is not in the proper interval, the only actions that should take place are displaying an error message and returning control back to the operating system.

If the value for sum is in the proper interval, the user should be prompted for a number of dimes d, a number of nickels n, and a number of pennies p. If the monetary value of the coins provided by the user equals sum, display the message "Yes" and exit the program. Otherwise display the message "No" and prompt the user one more time to enter a correct amount of coins.

Explanation / Answer

#include <iostream>
using namespace std;

int main() {
int sum,p,n,d;
   cout<<"Enter the sum. The sum should be in the interval 0..99 : ";
   cin>>sum;
   if(sum<0 || sum>99)
   return 0;
   while(1)
   {
   cout<<"Enter number of dimes d, a number of nickels n, and a number of pennies p: ";
   cin>>d>>n>>p;
       if((d+n+p)==sum)
       {
       cout<<"Yes ";
       return 0;
       }
       else
       {
       cout<<"No ";
       cout<<"Enter again ";
       }
   }
   return 0;
}

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