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

How would I write the program for Ch. 5 Programming Exercise (PE) # 28 with a do

ID: 3690045 • Letter: H

Question

How would I write the program for Ch. 5 Programming Exercise (PE) # 28 with a do while loop and with asking the user if they would like to run the program again at the end? This is for Malik's "C++ Programming: From Problem Analysis to Program Design" 7th Ed. How would I write the program for Ch. 5 Programming Exercise (PE) # 28 with a do while loop and with asking the user if they would like to run the program again at the end? This is for Malik's "C++ Programming: From Problem Analysis to Program Design" 7th Ed.

Explanation / Answer

Can you please attach PE 28, I did not get the book "C++ Programming: From Problem Analysis to Program Design" 7th Edition. As per understanding the given Question, I answred as below: (I will answer the question once you post the question, if you want the answer differt)

General Syntax of do..while loop is as shown below:

do

{

..... Statement(s)

} while(condition);

In do.. while loop statement, the block of code executes atleast once then it checks the while condition. but in while loop, first it checks the condition then if the condition satisfy it will executes the statemsnts in the loop. So if the condition fails to saisfy for the first time it won't execute the while loop statements.

#include <iostream>
#include <conio.h>
using namespace std;

void main()
{
   char choice = '';
   int i = 0;
   do
   {
      
       cout << "Iteration Number: " << i << endl;
       cout << "Would you like to run this program again? (y/ other char): ";
       cin >> choice;
       i++;
   } while (choice == 'y' || choice == 'Y');
   cout <<endl<< "do..While loop ended successfully!!";
}

Output:

Iteration Number: 0
Would you like to run this program again? (y/ other char):y

Iteration Number: 1
Would you like to run this program again? (y/ other char):n

do..While loop ended successfully!!

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