All pastes #551993 Raw Edit

Miscellany

public c v1 · immutable
·published 2007-06-09 01:39 UTC
rendered paste body
#include <stdio.h>#include <string.h>/*function prototypes*/void userInput(char n[][21], double r[], double h[], int loop);void printOut(char name[][21], double rate[], double hours[], int loop);/*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, rate, hours, i);		if(rate[i] == -1 || hours[i] == -1)			break;   //if input is -1, exit for loop		printOut(name, rate, 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[], int loop){	printf("Please enter your name: ");	scanf("%s", &n[loop]);   	printf("Please enter hourly rate: ");	scanf("%lf", &r[loop]);	printf("Please enter hours worked: ");	scanf("%lf", &h[loop]);  }/*function to calculate the gross, base, and overtime pay*/double calcPay(double r[], double h[], int loop){	double total = 0.0, basePay = 0.0, overtimePay = 0.0;	if(h[loop] <= 40)  //if less than 40 hours worked, pay is the normal base pay	{		total = r[loop] * h[loop];		basePay = total;	}	else if (h[loop] > 40)  //if over 40 hours worked, pay includes overtime	{		basePay = 40*r[loop];   		overtimePay = 1.5*r[loop]*(h[loop] - 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[], int loop){		double amount = 0.0;	static double totalPay = 0.0;	printf("Pay to: %s\n", n[loop]); 	printf("Hours worked:		 %.2f\n", h[loop]); 	printf("Hourly rate:		$%7.2f\n", r[loop]);  	amount = calcPay(r, h, loop);	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");}