PayStub Help



}
Last edited on
Put your code (not all of it just the part you want to repeat) inside a while loop or do-while loop depending on what you want to achieve and every time check for your exit condition, use break to exit if you are checking the condition from inside the loop, here are some quick examples :

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>

int main ()
{
        int someVar;

        while (exit_condition)
        {
                cin >> someVar;
        }
}


Or

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>

int main ()
{
        int someVar;

        do
        {
                cin >> someVar;
        } while (exit_condition);
}


Or

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

int main ()
{
        int someVar;

       // in case your condition can't be checked except inside the
       // while loop which it is in your example i think

        while (1) // 1 is just like true
        {
                cin >> someVar;

                if (someVar == exit_command)
                {
                        break;
                }
        }
}


Also don't forget to reset variables that are used as counters or their initial value affects the program, either at the beginning of the loop or the end

Note : include your code between code tags so everyone can read it easily.
Last edited on
It's quite simple. You just create a do-while loop around whatever you want to be repeated. And you tell it to exit once something happens.

1
2
3
4
do{

   // code here
}(userPrompt != 0) // For example, this will run as long as userPrompts is not equal to 0. 


Please edit your post and use code-tags http://www.cplusplus.com/articles/jEywvCM9/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>

using namespace std;

//Tax Rate by Code...
const double FICArate = 0.062;
const double FMEDrate = 0.0145;
const double SITrate = 0.05;
const double FITrate = 0;
//Paycode by rate...
const double Mrate = 27.50;
const double Crate = 19.50;
const double Lrate = 10.35;
//Insurance Code
const double Acode = 25//The Payroll Calculator program to enter specific data.
.00;
const double Bcode = 15.00;
const double Ccode = 0.00;
//Tax Bracket for FIT
const double Bracket1 = 0.125;
const double Bracket2 = 0.22;
const double Bracket3 = 0.2935;


int main()
{
	char exit = 'n';

	while (exit == 'n')
	{
		//Variable declaration
		string empName;
		double empId =0;
		double hWorked=0;
		double hRate=0;
		double oTime = 0;
		double grossPay=0;
		double insDeduct=0;
		double FIT=0;
		double FICA=0;
		double SIT=0;
		double FMED=0;
		double netPay = 0.0;
		char employeeType;
		char choice;

		cout << fixed << showpoint;
		cout << setprecision(2);

		//Input information for Employee
		cout << "Enter Employee Name: ";
		getline(cin, empName);

		cout << "Enter Employee ID: ";
		cin >> empId;

		cout << "ENTER THE HOURS WORKED: ";
		cin >> hWorked;

		cout << "Enter Employee Type: ";
		cout << "M or m (a manager employee),";
		cout << "C or c (a contractor employee),";
		cout << "L or l (a level employee),";
		cin >> employeeType;

		cout << endl;
		cout << "A or a ($25.00 Insurance Deduction),"<<endl;
		cout << "B or b ($15.00 Insurance Deduction),"<<endl;
		cout << "C or c ($0.00 Insurance Deduction),"<<endl;
		cin >> choice;

		cout << endl;

		switch (employeeType)
		{
		//Manager Hourly Pay Rate
		case 'm':
		case 'M':
			hRate = Mrate;
			break;

		//Contrator Hourly Pay Rate
		case 'c':
		case 'C':
			hRate = Crate;
			break;

		//Level Hourly Pay Rate
		case 'l':
		case 'L':
			hRate = Lrate;
			break;

		default:
			hRate = Lrate;
		}

		if (choice == 'A')
			insDeduct = 25.00;
		if (choice == 'B')
			insDeduct = 15.00;
		if (choice == 'C')
			insDeduct = 0.00;

		//Caculates employee regular pay with overtime.
		//The first 8 hours are calculated at hRate + 50%.
		//Any hours beyond are double time + grosspay.

		if (hWorked <= 40)
		{
			grossPay = hRate * hWorked;
		}

		if (hWorked > 40 && hWorked <= 48)
		{
			grossPay = 40 * hRate + 1.5 * hRate *(hWorked - 40);
		}

		if (hWorked > 48)
		{
			grossPay = 40 * hRate + 1.5 * hRate *(hWorked - 40);
			grossPay = grossPay + 2.0*hRate*hWorked*(hWorked - 48);
		}

		if (grossPay > 0 && grossPay < 350.00)
			FIT = (grossPay * Bracket1);

		if (grossPay > 350.00 && grossPay < 1000.00)
			FIT = (grossPay * Bracket2);


		if (grossPay > 1000.00)
			FIT = (grossPay * Bracket3);

		FICA = FICArate * grossPay;
		FMED = FMEDrate * grossPay;
		SIT = SITrate * grossPay;
		insDeduct = choice - grossPay;

		netPay = grossPay - FIT - FICA - FMED - SIT - insDeduct;

		cout << fixed << showpoint;

		cout << "----------------------------------------------------------" << endl;

		cout << "ID Name Gross FIT FMED FICA SIT Ins Net " << endl;
		cout << endl;
		cout << setw( 9) << setprecision(2) << empId
		<< setw(10) << setprecision(2)<< empName
		<< setw( 9) << setprecision(2)<< grossPay
		<< setw(10) << setprecision(2)<< FIT
		<< setw( 9) << setprecision(2)<< FICA
		<< setw(10) << setprecision(2)<< FMED
		<< setw( 9) << setprecision(2)<< SIT
		<< setw(10) << setprecision(2)<< insDeduct
		<< setw( 9) << setprecision(2)<< netPay
		<< endl;
		cout << endl;
		cout << "--------------------------------------------------" << endl;

		// Loop termination
		cout << "Do want to exit (n/y)" << endl;
		cin >> exit;
	}

	system("pause");
	return (0);
}
Thank you for the help kbw (7682) but the suggested did not run.
Thank you for the help kbw. I am sorry it did work.
Topic archived. No new replies allowed.