1 small problem. can u fix it please?? =)

Ok all, new to programming, but feeling better about it. ive written this program for my class and i feel very good about it. however, there is one issue im having trouble making right. if you run the program you will see what im talking about, but essentially here it is...

this is a simple program that calculates 4 differant pay rates based on the type of employee that is entered within the switch statement. that said, part of it is me telling the program to figure the pay rate on a 40 hr work week plus overtime. the problem is this. i can get the program to kick back if someone enters more than 40 hours on a work week, and i can get it to kick back if the user enters says -3 hours. However if say they enter 45 hrs, but then enter -3 right after in the next line, it accepts it. the same if first they enter -7 hrs, but then enter 1000 it accepts that. for some reason the statements are not connecting to one another and thats where my issue is. how do i make it recognize both, instead of only 1 or the other. Listed below is my program and any help is truly appreciated.

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
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{

float reghours=0, overtime=0, overtimepay, grossweeklysales, commisionpay, commision, pieces, grosspay, hourlywage=0, piecepay;
int n;
n = 1,2,3,4;
enum Etype {Manager, Hourly, Commision, Piece};


cout<<" Please enter the approprate employee code to be figure.  Enter 1 for Managers, 2 for Hourly workers, 3 for Commissioned workers, and 4 for Piece workers: ";
cin>> n;

switch (n) {
	case 1:
		cout<< "The Manager will receive 1000 dollars for the week.";
		break;
	case 2:
		cout<< "Please enter the number of hours worked between 1 and 40: ";
		cin>>reghours;

		do {
		if (reghours >=41) {
			cout<< "Hours must be between 1 and 40, please reenter hours worked: ";
			cin>>reghours;
		}
		} while (reghours >=41);

		do {
			if (reghours <=0) {
				cout<< "Hours must be between 1 and 40. Please reenter hours worked: ";
				cin>>reghours;
			}
		} while (reghours <=0);
		cout<< "Please enter the number of hours worked over 40: ";
		cin>>overtime;

		do {
			if (overtime >=81) {
				cout<< "Overtime hours cannot be greater than 80.  Please reenter the number of overtime hours worked: ";
				cin>>overtime;
			}
		} while (overtime >=81);

		cout<< "Please enter the hourly rate pay to this employee: ";
		cin>>hourlywage;

		do {
			if (hourlywage >=251) {
				cout<< "No employees within this company are paid more than 250 dollars per hour.  Please reenter the hourly rate for this employee: ";
				cin>>hourlywage;
			}
		} while (hourlywage >=251);

		do {
			if (hourlywage <=0) {
				cout<< "Hourly wage must be a minimum of 1 dollar per hour.  Pleaser reenter the hourly rate for this employee: ";
				cin>>hourlywage;
			}
		} while (hourlywage <=0);

		overtimepay = overtime * (1.5 * hourlywage);
		grosspay = (reghours * hourlywage) + overtimepay;

		cout<< "This employees pay for the week is: " << grosspay << endl;
		break;
	case 3:
		cout<< "Please enter the amount of gross weekly sales this employee contibuted to: ";
		cin>>grossweeklysales;

		commisionpay = (grossweeklysales / 5.7) + 250;

		cout<< "This emloyees pay for the week is: " << commisionpay <<endl;
		break;

	case 4:
		cout<< "please enter the number of peices this employee completed: ";
		cin>>pieces;

		do {
			if (pieces >= 100); {
			cout<< "Employees are not allowed to produce more than 100 units per week.  Please reenter the number of units produced this week: ";
			cin>>pieces;
		}
		} while (pieces >=101);

		do {
			if (pieces <0); {
				cout<< " Employees cannot produce a negative number of pieces.  Please reenter the number of pieces produced: ";
				cin>>pieces;
			}
		} while (pieces <0);

		piecepay = pieces * 50;

		cout<< "This employees pay for the week is: " << piecepay <<endl;
		break;


}




}

		
You don't need two do-while loops for each thing to check. You can use || to check for two conditions in one statement. For example
1
2
3
4
5
6
if( hourlywage >= 251 || hourlywage <= 1 ) {
   // invalid input
}
else {
   // correct input
}


Out of curiosity, what IDE and compiler are you using? You have a whole wack of warnings that should be reported and fixed. You've got unreferenced variables, empty control statements (lines 84 and 91) and type mismatches.

Also, cin is scary (as I told you in your other thread about this program), use getline(), read the thing i referred you to.

Basically, you have more than "one small problem"
Last edited on
Topic archived. No new replies allowed.