Question

c++ Convert the following for loop to a while loop: for (int x = 50; x...

c++

Convert the following for loop to a while loop:

for (int x = 50; x > 0; x-=2)

{

     cout << x << " seconds to go.\n";

}

Homework Answers

Answer #1

int x = 50;
while (x > 0) {
    cout << x << " seconds to go.\n";
    x -= 2;
}

#include <iostream>

using namespace std;

int main() {
    int x = 50;
    while (x > 0) {
        cout << x << " seconds to go.\n";
        x -= 2;
    }
    return 0;
}

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
convert the while loop into for loop x = int(input('Enter initial value: ')) count = 0...
convert the while loop into for loop x = int(input('Enter initial value: ')) count = 0 if(x<1): print('Error') exit() print('Initial value is: ',x,' ',end='') while(x!=1): if(x%2==0): x=x/2 else: x=3*x+1 count+=1 if(x!=1): rint('Next value is: ',int(x),' ',end='') else: print('Final value ',int(x),', ',end='') print('number of operations performed ',int(count),' ',end='') break
Do While loop on C++ I need to program a do while loop in which the...
Do While loop on C++ I need to program a do while loop in which the user have to choose between option A,a, B,b or C,c. I need a do while loop that if other letter (different from options is choose) the loop print a cout saying "Invalid selection. Plese, enter the selection again.   I have one, but isn't working well int main() { char option; do { cout<<"Please choose one of the following options: "<<endl<<endl; cout<<"Option A - Julian...
(c programming) Examine the following code: int x = 5; while(x = 0){ x += x;...
(c programming) Examine the following code: int x = 5; while(x = 0){ x += x; } while(x-- > 5){} What is the final value of x? Does the assignment expression in the first loop occur and if so, what value does it evaluate to?
How do I convert this while loop to tail recursion? private void markForward (int row, int...
How do I convert this while loop to tail recursion? private void markForward (int row, int col, int distance,            int oldMarker, int newMarker) {       while (col+ distance < BOARD_SIZE) {        if(board[row][col+ distance] == oldMarker ) {            board[row][col+ distance] = newMarker;            //markForward (row, col, distance, oldMarker, newMarker);        }        if(row+distance < BOARD_SIZE && board[row+distance][col+distance] == oldMarker) {            board[row+distance][col+distance] = newMarker;       ...
True or False? a. int i = 0; while(i <= 20); { i = i+5; cout...
True or False? a. int i = 0; while(i <= 20); { i = i+5; cout << i << " "; } The above loop is an infinite loop. for(int i =5; i>=1 ; i++) { cout << i << endl; } The above loop is an infinite loop.
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...
(True or False) The following is an infinite loop. for(int i = 0; i < 5;...
(True or False) The following is an infinite loop. for(int i = 0; i < 5; --i) { cout << "Haha"; }
IN C++ AS SIMPLE AS POSSIBLE ______ Re-write the given function, printSeriesSquareFifth,  to use a while loop...
IN C++ AS SIMPLE AS POSSIBLE ______ Re-write the given function, printSeriesSquareFifth,  to use a while loop (instead of for). • The function takes a single integer n as a parameter • The function prints a series between 1 and that parameter, and also prints its result • The result is calculated by summing the numbers between 1 and n (inclusive). If a number is divisible by 5, its square gets added to the result instead. • The function does not...
Please find the errors of the following code a) int x[5]; int k = 10; for...
Please find the errors of the following code a) int x[5]; int k = 10; for (k = 0; k <= 5; k++) { x[k] = k -1; } b) int x[5]; for (k = 1; k <= 5; k++) { cout << x[k-1] << endl; } c) int x[5]={1,2,3,4,5}, y[5]; y = x; for (k = 0; k < 5; k++) { cout << y[k] << endl; } d) int size; cin >> size; int myArr[size];
Convert the factorial program to do-while loop and for loop programs
Convert the factorial program to do-while loop and for loop programs