It's hackish, but it works now. If I remember I'll come up with a more elegant solution tommorow, or you can.
Code:
#include <stdio.h>
int main()
{
double weeklysale, salary1, salary2, salary3 = 0, salary4, rate;
int id, paycode = 0, hours, itemsproduced;
printf( "\nEnter employee's ID number (-1 to end): ");
scanf( "%d", &id );
if ( id > 99 ) {
printf ("Wrong ID Number. Please enter a new one (2 digits max.): ");
scanf( "%d", &id );
}
while ( paycode != -1 ) {
printf( "\nSelect a Paycode:\n1 is for managers\n2 is for commission workers\n" );
printf( "3 is for hourly workers\n4 is for pieceworkers\n\n" );
printf( "Enter chosen Paycode: ");
scanf( "%d", &paycode );
switch ( paycode ) {
case 1:
paycode = 1;
break;
case 2:
paycode = 2;
break;
case 3:
paycode = 3;
break;
case 4:
paycode = 4;
break;
case '\n':
case ' ':
break;
default:
printf( "Incorrect Paycode number entered. " );
printf( "\nEnter new Paycode number: " );
break;
}
if ( paycode == 1 ){
salary1 = 2500.00;
printf( "Salary is $%.2f\n\n\n", salary1 );
}
if ( paycode == 3 ){
printf( "Enter # of hours worked: " );
scanf( "%d", &hours );
printf( "Enter hourly rate of the worker ($00.00): " );
scanf( "%lf", &rate );
if ( hours <= 40 )
salary3 = hours * rate;
if ( hours > 40 )
salary3 = (hours - 40) * (1.50 * rate) + (40 * rate);
printf( "Salary is $%.2f\n\n\n", salary3 );
}
if ( paycode == 2 ) {
printf( "Enter gross weekly sales of the worker ($00.O0): ");
scanf( "%lf", &weeklysale );
salary2 = 250.00 + ( 6.5 * weeklysale ) / 100;
printf( "Salary is $%.2f\n\n\n", salary2 );
}
if ( paycode == 4 ){
printf( "Enter # of items produced by the worker: ");
scanf( "%d", &itemsproduced );
printf( "Enter hourly rate of the worker ($00.00): " );
scanf( "%lf", &rate );
salary4 = itemsproduced * rate;
printf( "Salary is $%.2f\n\n\n", salary4 );
}
}
return 0;
}
-Prelude