Question

Using a for Loop visual c++ Summary In this lab the completed program should print the...

Using a for Loop visual c++

Summary

In this lab the completed program should print the numbers 0 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

Write a for 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 Code" button at the bottom of the screen. Is the output the same?

___________________________________________________

// Output: Prints the numbers 0 through 10 along with their 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;                  // Numbers 0 through 10

   int byTen;                       // Stores the number multiplied by 10

   int byTwo;                       // Stores the number multiplied by 2

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

   // This is the work done in the housekeeping() function

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

                       

   // This is the work done in the detailLoop() function

   // Write your for loop here.

  

   }/ This is the work done in the endOfJob() function

   return 0;

} // End of main()

Homework Answers

Answer #1

Program:

#include <iostream>
#include <string>
using namespace std;

int main()
{
string head1 = "Number: ";
string head2 = "Multiplied by 2: ";
string head3 = "Multiplied by 10: ";   
int numberCounter; // Numbers 0 through 10
int byTen; // Stores the number multiplied by 10
int byTwo; // Stores the number multiplied by 2
const int NUM_LOOPS = 10; // Constant used to control loop

// This is the work done in the housekeeping() function
cout << "0 through 10 multiplied by 2 and by 10." << endl;

// This is the work done in the detailLoop() function
for(int numberCounter=0;numberCounter<NUM_LOOPS;numberCounter++)
{
    byTwo=numberCounter*2;
    byTen=numberCounter*10;
    cout<<head1<<numberCounter<<" "<<head2<<byTwo<<endl;
    cout<<head1<<numberCounter<<" "<<head3<<byTen<<endl;
  
}// This is the work done in the endOfJob() function
return 0;
} // End of main()

___________________

output:

_______________Thank You

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In C++ Please, In the main(), below, write a program that prompts for (1) how many...
In C++ Please, In the main(), below, write a program that prompts for (1) how many values to sum, and then (2) uses a summing loop to prompt for and add up 5 numbers. #include <iostream> #include <iomanip> using namespace std; int main() { < your answer goes here> return 0; }
In the main(), below, write a program that prompts for (1) how many values to sum,...
In the main(), below, write a program that prompts for (1) how many values to sum, and then (2) uses a summing loop to prompt for and add up 5 numbers. #include <iostream> #include <iomanip> using namespace std; int main() {     < your answer goes here> return 0; }
im trying to make a program that will use a while loop to repeatedly ask a...
im trying to make a program that will use a while loop to repeatedly ask a user for a test score. Use a counter to exit the loop when the user has entered 10 test scores. The loop is to figure out the total of all the scores and the highest score. it must use a while loop please explain problems in code the bottom code is my work done but does not work. #include <iostream> using namespace std; int...
Implement the body of the swap function using the indirection operator // finish this program so...
Implement the body of the swap function using the indirection operator // finish this program so that the values of // x and y are swapped in main(). #include <iostream> using namespace std; void swap(int* first, int* second) { // IMPLEMENT THIS FUNCTION // YOUR CODE GOES HERE } int main() { int x = 9; int y = 2; swap(&x, &y); cout << "x: " << x << endl; cout << "y: " << y << endl; // if...
How to trace a c++ program by hand #include<iostream> using namespace std;    class Test {...
How to trace a c++ program by hand #include<iostream> using namespace std;    class Test {     int value; public:     Test(int v); };    Test::Test(int v) {     value = v; }    int main() {     Test t[100];     return 0; } _______________ #include <iostream> using namespace std; int main() { int i,j; for (i=1; i<=3; i++) { for(j=1; j<=i; j++ ) { cout<<"*"; } cout << "\n";   } return 0; }
Write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Follow...
Write a while loop that prints userNum divided by 2 (integer division) until reaching 1. Follow each number by a space. Example output for userNum = 40: 20 10 5 2 1 ..... my code: #include <iostream> using namespace std; int main() { int userNum; userNum = 40; /* Your solution goes here */ while (userNum != 1){ userNum = userNum/2; cout << userNum << " ";   } cout << endl; return 0; } ........ but as a result i...
11. 4.21 (What Does this Program Do?) What does the following program print? 1 // Exercise...
11. 4.21 (What Does this Program Do?) What does the following program print? 1 // Exercise 4.21: Mystery2.cpp 2 #include <iostream> 3 using namespace std; 4 5 int main() { 6 unsigned int count{1}; 7 8 while (count <= 10) { 9 cout << (count % 2 == 1 ? "****" : "++++++++") << endl; 10 ++count; 11 } 12 }
using java LO: (Analyze) Students will fix a loop that runs forever. This program runs the...
using java LO: (Analyze) Students will fix a loop that runs forever. This program runs the countdown sequence for a rocket launch. However, it seems to loop infinitely. Fix the program so it counts down and terminates properly. starter code : import java.util.Scanner; /* * Counts down to a blastoff, starting from a given number. */ public class Countdown {    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        int countdown = 0;...
Please provide answer in the format that I provided, thank you Write a program that prompts...
Please provide answer in the format that I provided, thank you Write a program that prompts the user to input a string. The program then uses the function substr to remove all the vowels from the string. For example, if str=”There”, then after removing all the vowels, str=”Thr”. After removing all the vowels, output the string. Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. You must...
Lab 6    -   Program #2   -   Write one number to a text file. Use the write()...
Lab 6    -   Program #2   -   Write one number to a text file. Use the write() and read() functions with binary                                                        data, where the data is not char type.              (Typecasting is required) Fill in the blanks, then enter the code and run the program. Note:   The data is int type, so typecasting is            required in the write() and read() functions. #include <iostream> #include <fstream> using namespace std; int main() {    const int SIZE = 10;   ...