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

Modify the C++ program below so that it continues to divide two numbers until th

ID: 3693998 • Letter: M

Question

Modify the C++ program below so that it continues to divide two numbers until the user enters the character q (as a numerator or denominator) to terminate program execution.

#include
using namespace std;
int main()

{

   int numerator, denominator;
   bool needDenominator = true;
   cout << " Enter a numerator (whole number only): ";
   cin >> numerator;
   cout << "enter a denominator (whole number only): ";
   while (needDenominator)
   {

       cin >> denominator;
       try
       {
           if (denominator == 0)
               throw denominator;
       }
       catch (int e)
       {
           cout << " A denominator value of " << e << "is invalid." << endl;
           cout << "Please reenter the denominator(whole number only): ";
           continue;
       }
       cout << numerator << '/' << denominator
           << " = " << double(numerator) / double(denominator) << endl;
       needDenominator = false;
   }

  
   system("PAUSE");
   return 0;
}

Explanation / Answer

Answer for Question:

Updated the code is given above with do while loop with choice of excution of programe.

See the below updated code..

#include<iostream>
using namespace std;
int main()
{
int numerator, denominator;
bool needDenominator = true;
char ch = 'a';
cout << " Enter a numerator (whole number only): ";
cin >> numerator;
cout << "enter a denominator (whole number only): ";
do
{
cin >> denominator;
try
{
if (denominator == 0)
throw denominator;
}
catch (int e)
{
cout << " A denominator value of " << e << "is invalid." << endl;
cout << "Please reenter the denominator(whole number only): ";
continue;
}
cout << numerator << '/' << denominator
<< " = " << double(numerator) / double(denominator) << endl;
needDenominator = false;
   cout<<"you want quit the loop press q or Q or continue to press any key "<<endl;
   cin>>ch;

}while(ch !='q' || ch!='Q');


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