Concept explainers
Rewrite the following code, converting the while loop to a do-while loop:
char doAgain = 'y';
int sum = 0;
cout << "This code will increment sum 1 or more times.\n";
while ((doAgain == 'y') || (doAgain == 'Y'))
{ sum++;
cout << "Sum has been incremented. Increment it again(y/n)? ";
cin >> doAgain;
}
cout << "Sum was incremented " << sum << " times.\n";
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Starting Out With C++: Early Objects, Student Value Edition & Myprogramminglab With Pearson Etext -- Standalone Access Card Package, 9/e
Additional Engineering Textbook Solutions
Starting Out With Visual Basic (7th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
Starting Out with Java: From Control Structures through Objects (6th Edition)
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Starting Out with C++ from Control Structures to Objects (8th Edition)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
- Write the following for loop as a while loop. for (int count = 1; count <= 10; count++) cout << count << endl ;arrow_forwardConvert the following while loop to a do-while loop: int x = 1; while (x > 0) { cout << "enter a number: "; cin >> x; cout << "the number you just entered is: " << x; }arrow_forwardConvert the following for loop statement to a while loop and to a dowhile loop:long sum = 0; for (int i = 0; i <= 1000; i++) sum = sum + i;arrow_forward
- a. A bowling team consists of five players. Each player bowls three games. Write a program that uses a nested loop to enter each player's individual scores and then computes and displays the average score for each bowler. Assume that each bowler has the following scores. Use two different loop structures for outer loop and inner loop. For example, if you use "for" as the outer loop structure, the inner loop should be "while" or "do.... while". 1st bowler: 286 2nd bowler: 212 3rd bowler: 252 232 4th bowler: 192 201 265 215 216 235 5th bowler: 186 252 186 236 272 b. Modify the program written for Exercise 3a to calculate and display the average team score. (Hint: Use a second variable to store the total of all the players' scores.)arrow_forwardIdentify the issues in the following loops/if statement and explain why they are occuring. Then write corrected versions of each loop/if statement. int num = 5; while (num > 10) { cout << num << endl; num++; } int countdown = 5; while (countdown > 0) { cout << countdown << endl; countdown -= 2; } int faxulty = 7; int students = 12; if (faculty + students) { cout << "we have the same number of " << "faculty and sudents!" << endl; } else { cout << "we do not have the same number of " << "faculty and students." << endl; }arrow_forward19.1 LAB: Count multiples Write a program that takes three integers as input: low, high, and x. The program then outputs the number of multiples of x between low and high inclusive. Ex: If the input is: 1 10 2 the output is: 5 Hint: Use the % operator to determine if a number is a multiple of x. Use a for loop to test each number between low and high. The code I put here doesn't work. Use Python to help me with this, please.arrow_forward
- Consider the following for loop. int j, s;s = 0;for (j = 1; j <= 10; j++)s = s + j * (j - 1);In this for loop, identify the loop control variable, the initialization statement, loop condition, the update statement, and the statement that updates the value of s.arrow_forwardCODE USING C++ 3. Place Values by CodeChum Admin Manipulating values from a series of numbers is fun, but let's try exploring the use of loops a little more. How about printing out each digit of a number by place values, in ascending order? Instructions: Create a variable and input a random positive integer. Using while loop, print out each digit of the inputted integer in separate lines, starting from its rightmost digit until the leftmost digit of the number. Tip: Use % 10 to get the rightmost digit, and / 10 to remove it from the number. Another tip: don't forget to consider the case wherein the input is `0` Input A line containing an integer. 214 Output Multiple lines containing an integer. 4 1 2arrow_forwardC++ Integers firstNum and secondNum are read from input. Complete the inner while loop so the inner loop executes firstNum * (secondNum + 1) times. Ex: If the input is 6 3, then the output is: Inner loop ran 24 timesarrow_forward
- 19.1 LAB: Count multiples Write a program that takes three integers as input: low, high, and x. The program then outputs the number of multiples of x between low and high inclusive. Ex: If the input is: 1 10 2 the output is: 5 Hint: Use the % operator to determine if a number is a multiple of x. Use a for loop to test each number between low and high. The code I used doesn't work. Use Python to help me with this, please.arrow_forwardRewrite the following for loop using a while loop. Assumethe variable, x, has been declared as an integer. for (x = 300; x >= 1; x = x - 3) cout << x << endl;arrow_forwardWhat is the minimum number of iterations required to exit the following loop? double vall=0; bool Done = false; while (! Done) { vall += rand () %5; if (vall>=10) Done= true; }arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT