Help

Could someone help me with this code i have the application working properly but my professor said he would like a "do while" in it could someone help me with this please

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 #include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
	int payroll = 0;
	int storePayroll = 0;
	int totalPayroll = 0;
	for (int store = 1; store < 4; store += 1)
	{
		cout << "      First Payroll (-1 to end): Store " << store << ":";
		cin >> payroll;
		while (1)
		{
			storePayroll += payroll;
			cout << "Next payroll amount (-1 to end): Store " << store << ":";
			cin >> payroll;
			if (payroll == -1) 
			{
				break;
			}
		}//end while

		totalPayroll + storePayroll;
		cout << "Stores current total payroll: $" << storePayroll << endl;
	} //end for


	system("pause");
	return 0;
}
my professor said he would like a "do while" in it


well, lines 15 to 24 would be suitable.

Remove these lines
20
21
22
23
	if (payroll == -1) 
	{
		break;
	}


and replace while (1) { /* stuff */ }
with
do { /* stuff */ } while (payroll != -1);

See tutorial for description of how it works and examples:
http://www.cplusplus.com/doc/tutorial/control/
Last edited on
Topic archived. No new replies allowed.