Public feed #532658

Something

public text v1 · immutable
Raw Edit
·published 2007-06-03 06:25 UTC
rendered paste body
#include <stdio.h>
#include <string.h>

int main (void)
{
	char name[5][21];
	double rate[5], hours[5];
	double total = 0.0, taxes = 0.20; 
	double basePay = 0.0;

	for(int i=0; i<5; i++)
	{
		printf("Please enter your name: ");

		int j = 0;
		do{
			scanf("%c", &name[i][j]);
			j++;
		}while(name[i][j-1] != '\n');
		do{
			name[i][j-1] = ' ';
			j++;
		}while(j<21);
		name[i][20] = '\0';

		printf("Please enter hourly rate: ");
		scanf("%lf", &rate[i]);
		if(rate[i] == -1)
			break;
		printf("Please enter hours worked: ");
		scanf("%lf", &hours[i]);
		if(hours[i] == -1)
			break;

		printf("\n");
		printf("Write paycheck to: ");
		j = 0;
		do{
			printf("%c", name[i][j]);
			j++;
		}while(name[i][j] != ' ');
		printf("\n");
		printf("Hours worked: %g\n", hours[i]);
		printf("Hourly rate: $%.2f\n", rate[i]);

		double overtimePay = 0.0;

		if(hours[i] <= 40)
		{
			total = rate[i] * hours[i];
			basePay = total;
		}
		else if (hours[i] > 40)
		{
			basePay = 40*rate[i];
			overtimePay = 1.5*rate[i]*(hours[i] - 40);
			total = basePay + overtimePay;
		}

		printf("Gross pay: $%.2f\n", total);
		printf("Base pay: $%.2f\n", basePay);
		printf("Overtime pay: $%.2f\n", overtimePay);
		printf("Taxes paid: $%.2f\n", taxes*total);
		printf("Net pay: $%.2f\n", total-taxes*total);
		printf("\n");
	}
	return 0;
}