All pastes #552064 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-06-09 02:35 UTC
rendered paste body
#include <stdio.h>
#include <string.h>

/*function prototypes*/
void userInput(char n[21], double r, double h);
void printOut(char n[21], double r, double h);

/*function main begins program execution*/
int main (void)
{
	/*array declarations*/
	char name[5][21];    
	double rate[5], hours[5];   

	for(int i=0; i<5; i++)  //for loop will fill arrays and print 5 times
	{
		userInput(name[i], rate[i], hours[i]);
		if(rate[i] == -1 || hours[i] == -1)
			break;   //if input is -1, exit for loop

		printOut(name[i], rate[i], hours[i]);
	}//ends for loop
	return 0;
}

/*function to prompt user for name, rate, and hours worked*/
void userInput(char n[21], double r, double h)
{
	printf("Please enter your name: ");
	scanf("%s", &n);   
	printf("Please enter hourly rate: ");
	scanf("%lf", &r);
	printf("Please enter hours worked: ");
	scanf("%lf", &h);  
}

/*function to calculate the gross, base, and overtime pay*/
double calcPay(double r, double h)
{
	double total = 0.0, basePay = 0.0, overtimePay = 0.0;

	if(h <= 40)  //if less than 40 hours worked, pay is the normal base pay
	{
		total = r * h;
		basePay = total;
	}
	else if (h > 40)  //if over 40 hours worked, pay includes overtime
	{
		basePay = 40*r;   
		overtimePay = 1.5*r*(h - 40); 
		total = basePay + overtimePay;
	}

	printf("Gross pay:		$%7.2f\n", total);  
	printf("Base pay:		$%7.2f\n", basePay); 
	printf("Overtime pay:		$%7.2f\n", overtimePay); 

	return total;
}

double taxes(double pay)
{
	return 0.20*pay;
}

void printOut(char n[21], double r, double h)
{	
	double amount = 0.0;
	static double totalPay = 0.0;

	printf("Pay to: %s\n", n); 
	printf("Hours worked:		 %.2f\n", h); 
	printf("Hourly rate:		$%7.2f\n", r);  

	amount = calcPay(r, h);
	totalPay+=amount;

	printf("Taxes paid:		$%7.2f\n", taxes(amount));    
	printf("Net pay:		$%7.2f\n", amount-taxes(amount));
	printf("Total payout so far: %.2f\n", totalPay);
	printf("\n");
}