Question

In: Computer Science

USING a LOOP for C++ In this lab the completed program should print the numbers 0...

USING a LOOP for C++ 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 button at the bottom of the screen. Is the output the same? prewritten code is: // NewMultiply.cpp - This program prints the numbers 0 through 10 along // with these values multiplied by 2 and by 10. // Input: None // Output: Prints the numbers 0 through 10 along with their values multiplied by 2 and by 10. #include #include 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()

Solutions

Expert Solution

#include <iostream>

using namespace std;

int main()
{
string head1 = "Number: ";
string head2 = "Multiplied by 2: ";
string head3 = "Multiplied by 10: ";
int numberCounter;
int byTwo;
int byTen;
const int NUM_LOOPS = 10;
cout << "0 through 10 multiplied by 2 and by 10." << endl;
//write a for loop
for(numberCounter=0;numberCounter<=NUM_LOOPS;numberCounter++)
{
byTwo=2*numberCounter;
byTen=10*numberCounter;
//print the values according to a specific format
cout<<head1<<numberCounter<<" "<<head2<<byTwo<<" "<<head3<<byTen<<endl;
}

return 0;
}


comment if any questions


Related Solutions

Write a program in Python that will print first 100 numbers of the following series: 0,...
Write a program in Python that will print first 100 numbers of the following series: 0, 1, 1, 2, 3, 5, 8……..
Using a “for loop” print all even numbers in range from 1 to 1000. Also, please...
Using a “for loop” print all even numbers in range from 1 to 1000. Also, please count and print how many even numbers you have found.
C++ In this lab you will be using nested for loops to print out stars in...
C++ In this lab you will be using nested for loops to print out stars in a Diamond pattern such as this: * *** ***** ******* ********* *********** ************* *************** ************* *********** ********* ******* ***** *** * For example , if number of rows=8 then the above pattern is derived. You are to take the input for the number of lines(rows) from a file named "input_diamond" and output the pattern into both the terminal and an output file named "output_diamond".
Write a Java program using jGRASP directions are as follows: Uses a while loop to print...
Write a Java program using jGRASP directions are as follows: Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop to print the numbers from 42 - 56. Uses a for loop to print the numbers from 87 - 95. Asks the user for 2 numbers. Uses a loop to print all numbers between the given numbers, inclusive. Note: Consider that your user's second number can be lower! (see example below) Note: Also consider...
(C++) Write a nested loop that reads an integer n (n>0) from the keyboard and print...
(C++) Write a nested loop that reads an integer n (n>0) from the keyboard and print out "n" lines as follows: 0 0 1 0 1 2 0 1 2 3 … 0 1 2 3 … n-1
(Do the algorithm and flowchart) Write a C++ program that reads integer numbers and print it...
(Do the algorithm and flowchart) Write a C++ program that reads integer numbers and print it in horizontal order of the screen
Write a program that uses a for loop to print One of the months of the...
Write a program that uses a for loop to print One of the months of the year is January One of the months of the year is February ...
public void printNumbers(int low, int high) { // using a for loop, print all numbers from...
public void printNumbers(int low, int high) { // using a for loop, print all numbers from low to high } public int sumOfNumbers(int n) { // using a for loop, calculate and return the sum of first n numbers // i.e n = 5, answer = 5+4+3+2+1 = 15 } public void printMultiplicationTable(int num) { // using a for loop, print the multiplication table of num (up to first 10!) // i.e. num = 5, 5*1=5, 5*2=10, 5*3=15, 5*4=20, 5*5=25,...
Write a program using c++. Write a program that uses a loop to keep asking the...
Write a program using c++. Write a program that uses a loop to keep asking the user for a sentence, and for each sentence tells the user if it is a palindrome or not. The program should keep looping until the user types in END. After that, the program should display a count of how many sentences were typed in and how many palindromes were found. It should then quit. Your program must have (and use) at least four VALUE...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create...
C++ program using Eclipse IDE The C++ program should have concurrency. The C++ program should create 2 threads that will act as counters. One thread should count down from 5 to 0. Once that thread reaches 0, then a second thread should be used to count up to 20.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT