Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C by Kris ( 7 years ago )
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
#define _CRT_SECURE_NO_WARNINGS
#define PAUSE system("pause")
#define CLS system("cls")
#define FLUSH myFlush()
void myFlush(){
while(getchar() != '\n');
}
//Functions
void displayMenu(){ //welcome message and stats(hourly wage and total hours)retrieval
CLS;
printf("Welcome! Here, you will find the following\n");
printf("[1]Hourly Rate\n");
printf("[2]Hours Worked\n");
printf("[3]Regular Pay\n");
printf("[4]Overtime Pay\n");
printf("[5]Gross Pay\n");
printf("[6]Federal Tax\n");
printf("[7]Medical Insurance\n");
printf("[8]Net Pay\n");
printf("[9]Quit\n\n");
printf("choose an option: ");
return;
}//end displayMenu
char getChoice(){ //user's input choice
char result;
displayMenu();
scanf("%c", &result);FLUSH;
return toupper(result);// return to the menu selection with capital letter
}//end getChoice
float hourlyRate(){ //user's pay per hour
float wageH;
printf("How much do you make per hour?:");
scanf("%.2f", &wageH);FLUSH;
printf("Okay. Your hourly rate is $%.2f", wageH);
return wageH;
}//end hourlyRate
int hoursWorked(){ //user's total hours worked
int hours;
printf("How many hours have you worked this week?:");
scanf("%i", &hours);FLUSH;
printf("\n Okay. You have worked %i hours this week", hours);
return hours;
}//end hoursWorked
float regularPay(){ //user's total pay for the week
float totalPay;
totalPay = wageH * hours;
printf("Your total pay is $%.2f", totalPay);
return totalPay;
}//end regularPay
float overtimePay(){ //user's overtime hours and overtime pay
int hoursOver = 0;
float otPay;
printf("How many hours overtime have you worked for this week?");
scanf("%i", &hoursOver);FLUSH;
otPay = wageH * 1.5 * hoursOver;
printf("Your overtime pay is be %.2f", otPay);
return otPay;
}//end overtimePaty
float grossPay(){ // user's gross pay
float gPay;
gPay = totalPay + otPay;
printf("Your gross pay is %.2f", gPay);
return gPay;
}//end grossPay
float federalTax(){ //user's federal tax deduction
float fedTax;
fedTax = gPay * 0.27;
printf("Your federal tax is %.2f", fedTax);
return fedTax;
}//end federalTax
float medicalInsurance(){ //user's medical insurance deduction
float medIns;
medIns = gPay * 0.14;
printf("Your medical insurance is %.2f", medIns);
return medIns;
}//end medicalInsurance
float netPay(){ //user's total net pay
float totalNet;
totalNet = gPay - (fedTax + medIns);
printf("Your total net pay is %.2f", totalNet);
return;
}//end netPay
main(){
//variables
char userChoice = ' ';
int value = 0;
//Menu
displayMenu();
do{
userChoice = getChoice();
switch(userChoice){
case '1':
hourlyRate(value);
case '2':
hoursWorked(value);
case '3':
regularPay(value);
case '4':
overtimePay(value);
case '5':
grossPay(value);
case '6':
federalTax(value);
case '7':
medicalInsurance(value);
case '8':
netPay(value);
case '9':
printf("Thanks for stopping by!", 'Y');
default:
printf("Welcome! Please enter a number between 1-8, or press 9 to quit:", 'Y');
}
}
while(userChoice != '9');
PAUSE;
}//end main
Revise this Paste