Explore BrainMass
Share

Three different looping examples in C++

This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

Design a While Loop that lets the user enter a number. The number should be multiplied by 10, and the result stored in a variable named product. The loop should iterate as long as product contains a value less than 100.

Design a For loop that calculates the total of the following series of numbers: 1/30+2/29+3/28+...30/1

Design a program with a loop that lets the user enter a series of numbers. Then user should enter -99 to signal the end of the series. After all the numbers have been entered, the program should display the largest and smallest numbers entered.

© BrainMass Inc. brainmass.com March 21, 2019, 5:07 pm ad1c9bdddf
https://brainmass.com/computer-science/cpp/three-different-looping-examples-209333

Solution Preview

For this posting I'll assume C++ but the loop concepts are nearly universal for the different common programming languages.

The following while loop reads in integers as long as the product of the entered number * 10 is less than 100.

int num;
int product = 0;
while (product < 100) {
cin >> num;
product = num * 10;
}

The loop ...

Solution Summary

This solution provides three different examples of using loops in C++.

$2.19