Question

Convert the while loop in the program below into a for loop. int Taylor = 10,...

Convert the while loop in the program below into a for loop.

int Taylor = 10, Justin = 6, Selena=3;

cout << “Que Pasa? ” << “\n\n”;

while (Selena > 0)

{

cout << Taylor << “@ “ << Justin << “\n” ;

--Selena;

Taylor++;

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Output:
--------
Que Pasa?

10@ 6
11@ 6
12@ 6

Explanation:
--------------
Before while loop "Que Pasa?\n\n" is printed. \n is a newline character
while loop trace here
Iteration 1
   Taylor = 10 and Justin = 6
   so, "10@ 6" is printed
   --Selena changes Selena to 2
   Taylor++ changes Taylor to 11
Iteration 2
   Taylor = 11 and Justin = 6
   so, "11@ 6" is printed
   --Selena changes Selena to 1
   Taylor++ changes Taylor to 12
Iteration 3
   Taylor = 12 and Justin = 6
   so, "12@ 6" is printed
   --Selena changes Selena to 0
   Taylor++ changes Taylor to 13
Add a comment
Know the answer?
Add Answer to:
Convert the while loop in the program below into a for loop. int Taylor = 10,...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Q. 07 (2 points) Convert the following while loop to a for loop: int count =...

    Q. 07 (2 points) Convert the following while loop to a for loop: int count = 0; while (count<50) cout<<"count iscounts endl count+

  • FOR C# PROGRAM Convert the following for loop to a while loop: for (int counter=0; counter<101;...

    FOR C# PROGRAM Convert the following for loop to a while loop: for (int counter=0; counter<101; counter++) { sum += counter; }

  • How many Iterations will this while loop perform? int ico), j(10); cout << "i = "...

    How many Iterations will this while loop perform? int ico), j(10); cout << "i = " << i << endl; cout << "j = " << j << endl; while (i > j) { cout << "j-" « j << endl; j += 2; cout << "i = " << i << endl; } cout << "i = << i << endl; cout << "j = " << j << endl; 5 6 C 8 10 Infinite times Does the...

  • c++ convert do while loop below to a for loop #define MAX VALUE 5 #define START...

    c++ convert do while loop below to a for loop #define MAX VALUE 5 #define START VALUE 5 //START_VALUE always <-MAX VALUE int main() convert do while loop below to a for loop int j - MAX VALUE; do cout <<<<endl; ; while > 0); I

  • in c++ language 1.Re-write the following for loop statement by using a while loop statement: int...

    in c++ language 1.Re-write the following for loop statement by using a while loop statement: int sum = 0; for(int i=0;i<=1000;i++){                 sum+=i; } 1 (b). Following is the main () function of a program. The program asks a user to enter 150 integers and print the largest integer user entered. int main() {    int score, highest;             //missing portion of the program             return 0;    } 1(c). Find the missing portion of the following code, so the...

  • Convert the following while loop into a for loop. int 1 - 50: int sum-07 while...

    Convert the following while loop into a for loop. int 1 - 50: int sum-07 while (sum < 1000) sum - sum + 1; Question 35 (2 points) Saved Given an int variable k that has already been declared, use a while loop to print a single line consisting of 80 dollar signs. Use no variables other than k. int sum = 0; for(int i = 100;sum < 10000;1-- sum = sum + i;

  • using C++ 1. Convert the following while loop into a for loop: int count = 0;...

    using C++ 1. Convert the following while loop into a for loop: int count = 0; while (count < 10) x = count + sin(x); y = count + cos(y); count++;

  • Can someone help me to convert from c++ to C program int main() { srand(time(0)); int...

    Can someone help me to convert from c++ to C program int main() { srand(time(0)); int playAgain; int PlayerScore=0; int computerScore= 0; int ties= 0; do { system("CLS"); Firstturn = rand()%(2-1+1)+1;// starting person. ComputerRandomPosition= rand()%(9-1+1)+1;// computer first pick- random gameWin=3; block1= '1'; block2= '2'; block3= '3'; block4= '4'; block5= '5'; block6= '6'; block7= '7'; block8= '8'; block9= '9'; //start of program cout<<"Welcome to Tic Tac Toe Game"<<endl<endl; cout<<"Player:"<<playerScore<<"Computer:"<<computerScore<<"Ties:"<<ties<<endl; if(Firstturn==1)// player first { cout<<"Please Select your a grid to place (X):"<<endl<<endl;...

  • 11) 16 pts. Convert the following for loop to a while loop. (You may want to...

    11) 16 pts. Convert the following for loop to a while loop. (You may want to do the following question first.) int mine [5] = {10, 11, 12); for (int j=1; j < 5; j++) cout <<j<< "" << mine[jl <<" " << end1; 12) 6 pts. What is the output of the previous question? 13) 4 pts. Circle the variables that would NOT cause syntax errors 2-smaTT , entry# break -my-int

  • C++ Visual Studio 1. How many iterations are in the following "while" loop? int i =...

    C++ Visual Studio 1. How many iterations are in the following "while" loop? int i = 0; while(i < 20) { ++i; } 2. How many iterations are in the following "for" loop? for(int i = 5; i < 17; i = i + 2) { // Work } How many times will '+' be printed? int i = 0; while(true) { if(i == 5) { break; } cout << "+"; ++i; } 3. How many times will '+' be...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT