Question & Answer: Write a program that achieves the following requirements: A while/do-While loop that will ask the user t…..

Write a program that achieves the following requirements 1. A while/do-While loop that will ask the user to input an integer on each iteration. The loop keeps a running total of the input and exits only when the total exceeds the first input times 10. 2. A for loop that does the exact same thing The program should print out the new total each time the total is input.Use C++ please. Thank you

Write a program that achieves the following requirements: A while/do-While loop that will ask the user to input an integer on each iteration. The loop keeps a running total of the input and exits only when the total exceeds the first input times 10. A for loop that does the exact same thing. The program should print out the “new total each time the total is input.

Expert Answer

 

1.

#include<iostream>
using namespace std;

main()
{
// declaring variables
int i, total, first, temp;

// taking user input of first number
cout << “Enter a number : ” ;
cin >> first;
total = first;

// taking user input if total hasn’t reached 10 times first
while(total < (first*10))
{
cout << “Enter a number : ” ;
cin >> temp;

total += temp;
}

}

Enter a number :  123
Enter a number :  12
Enter a number :  23
Enter a number :  100
Enter a number :  1000

2.

#include<iostream>
using namespace std;

main()
{
// declaring variables
int i, total, first, temp;

// taking user input of first number
cout << “Enter a number : ” ;
cin >> first;
total = first;
cout << “Total is ” << total << endl;
// taking user input if total hasn’t reached 10 times first
while(total < (first*10))
{
cout << “Enter a number : ” ;
cin >> temp;
total += temp;
// printing total
cout << “Total is ” << total << endl;
}

}

Enter a number :  123
Total is 123
Enter a number :  12
Total is 135
Enter a number :  23
Total is 158
Enter a number :  100
Total is 258
Enter a number :  1000
Total is 1258
Still stressed from student homework?
Get quality assistance from academic writers!