21.0k views
2 votes
In this lab, you work with the same C++ program you worked with in Labs 5-1 and 5-3. As in those earlier labs, the completed program should print the numbers 0 through 10, along with their values multiplied by 2 and by 10. However, in this lab you should accomplish this using a do while loop.

Instructions
Ensure the source code file named NewestMultiply.cpp is open in the code editor.

Write a do while loop that uses the loop control variable to take on the values 0 through 10.

In the body of the loop, multiply the value of the loop control variable by 2 and by 10.

Execute the program by clicking the Run button and verify that the output is correct.

In this lab, you work with the same C++ program you worked with in Labs 5-1 and 5-3. As-example-1
User Calvein
by
8.0k points

1 Answer

5 votes

Answer:

Here is an updated code for the NewestMultiply.cpp program that uses a do-while loop to print the numbers 0 through 10 along with their values multiplied by 2 and by 10:

Step-by-step explanation:

// NewestMultiply.cpp

// This program prints the numbers through 10 along

// with these values multiplied by 2 and by 10.

#include <iostream>

#include <string>

using namespace std;

int main()

{

string head1 = "Number:";

string head2 = "Multiplied by 2:";

string head3 = "Multiplied by 10:";

int numberCounter = 0;

int byTen = 0;

int byTwo = 0;

const int NUM_LOOPS = 11; // Constant used to control loop

cout << "0 through 10 multiplied by 2 and by 10." << endl;

// Print the headers

cout << head1 << "\t" << head2 << "\t" << head3 << endl;

// Print the numbers

numberCounter = 0;

do {

byTwo = numberCounter * 2;

byTen = numberCounter * 10;

cout << numberCounter << "\t" << byTwo << "\t\t" << byTen << endl;

numberCounter++;

} while (numberCounter < NUM_LOOPS);

return 0;

} // End of main()

User Aalmigthy
by
8.3k points

No related questions found