Using a for Loop Summary In this lab the completed program should print the numbers O through 10, along with their values multiplied by 2 and by 10. You should accomplish this using a for loop instead of a counter- controlled while loop. Instructions 1. Write a for loop that uses the loop control variable to take on the values O through 10. 2. In the body of the loop, multiply the value of the loop control variable by 2 and by 10. 3. Execute the program by clicking the Run button at the bottom of the screen. Is the output the same?

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter5: Repetition Statements
Section5.3: Interactive While Loops
Problem 5E
icon
Related questions
Question
100%
Using a for Loop
Summary
In this lab the completed program should print the numbers O
through 10, along with their values multiplied by 2 and by 10. You
should accomplish this using a for loop instead of a counter-
controlled while loop.
Instructions
1. Write a for loop that uses the loop control variable to take
on the values O through 10.
2. In the body of the loop, multiply the value of the loop control
variable by 2 and by 10.
3. Execute the program by clicking the Run button at the bottom
of the screen. Is the output the same?
Transcribed Image Text:Using a for Loop Summary In this lab the completed program should print the numbers O through 10, along with their values multiplied by 2 and by 10. You should accomplish this using a for loop instead of a counter- controlled while loop. Instructions 1. Write a for loop that uses the loop control variable to take on the values O through 10. 2. In the body of the loop, multiply the value of the loop control variable by 2 and by 10. 3. Execute the program by clicking the Run button at the bottom of the screen. Is the output the same?
NewMultiply.cpp
+
1 // NewMultiply.cpp - This program prints the numbers ® through 10 along
2 // with these values multiplied by 2 and by 10.
3 // Input:
None
4 // Output: Prints the numbers 0 through 10 along with their values multiplied by
7 #include <iostream>
8 #include <string>
9 using namespace std;
10
11 int main(()
12 {
13
14
string head1 = "Number: ";
string head2
string head3 =
15
"Multiplied by 2: ";
16
"Multiplied by 10: ";
// Numbers 0 through 1O
// Stores the number multiplied by 10
// Stores the number multiplied by 2
// Constant used to control loop
17
int numberCounter;
int byTen;
int byTwo;
18
19
20
const int NUM_LOOPS = 10;
21
// This is the work done in the housekeeping() function
cout << "0 through 10 multiplied by 2 and by 10." << endl;
|22
|23
24
// This is the work done in the detailloop() function
// Write your for loop here.
25
26
27 for(int 1 =0; i < NUM_LOOPS; i++){
28
cout << "Number is: "<< i <<" ";
29
cout << "Number by 2 is: "<< i*2 << byTwo;
30
cout << "Number by 10 is: "<< i*10 <<byTen; endl;
31
32 }
33
// This is the work done in the endOf Job() function
34
return 0;
35 } // End of main()
36
Transcribed Image Text:NewMultiply.cpp + 1 // NewMultiply.cpp - This program prints the numbers ® through 10 along 2 // with these values multiplied by 2 and by 10. 3 // Input: None 4 // Output: Prints the numbers 0 through 10 along with their values multiplied by 7 #include <iostream> 8 #include <string> 9 using namespace std; 10 11 int main(() 12 { 13 14 string head1 = "Number: "; string head2 string head3 = 15 "Multiplied by 2: "; 16 "Multiplied by 10: "; // Numbers 0 through 1O // Stores the number multiplied by 10 // Stores the number multiplied by 2 // Constant used to control loop 17 int numberCounter; int byTen; int byTwo; 18 19 20 const int NUM_LOOPS = 10; 21 // This is the work done in the housekeeping() function cout << "0 through 10 multiplied by 2 and by 10." << endl; |22 |23 24 // This is the work done in the detailloop() function // Write your for loop here. 25 26 27 for(int 1 =0; i < NUM_LOOPS; i++){ 28 cout << "Number is: "<< i <<" "; 29 cout << "Number by 2 is: "<< i*2 << byTwo; 30 cout << "Number by 10 is: "<< i*10 <<byTen; endl; 31 32 } 33 // This is the work done in the endOf Job() function 34 return 0; 35 } // End of main() 36
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Types of Loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage