|
-
June 29th, 2009, 11:12 PM
#1
1 small issue and im happy!!! =)
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.
#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;
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|