Last active
November 7, 2017 21:36
-
-
Save rszewczyk/01d996cf3ae832b805e8a8a839d69732 to your computer and use it in GitHub Desktop.
CMSC104 - homework 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
double calculatePay(double hourlyRate, double hoursWorked) | |
{ | |
double pay = 0; | |
if (hoursWorked > 40) | |
{ | |
pay = hourlyRate * 40 + (hoursWorked - 40) * 1.5 * hourlyRate; | |
} | |
else | |
{ | |
pay = hourlyRate * hoursWorked; | |
} | |
return pay; | |
} | |
int main() | |
{ | |
double hourlyRate = 0; | |
double hoursWorked = 0; | |
printf("Enter the hourly rate of pay for person 1: "); | |
scanf("%lf", &hourlyRate); | |
printf("Enter the number of hours worked by person 1 this week: "); | |
scanf("%lf", &hoursWorked); | |
double pay = calculatePay(hourlyRate, hoursWorked); | |
printf("Person 1 earned $%.2lf this week\n", pay); | |
printf("Enter the hourly rate of pay for person 2: "); | |
scanf("%lf", &hourlyRate); | |
printf("Enter the number of hours worked by person 2 this week: "); | |
scanf("%lf", &hoursWorked); | |
pay = calculatePay(hourlyRate, hoursWorked); | |
printf("Person 2 earned $%.2lf this week\n", pay); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
double calculatePay(double hourlyRate, double hoursWorked) | |
{ | |
double pay = 0; | |
if (hoursWorked > 40) | |
{ | |
pay = hourlyRate * 40 + (hoursWorked - 40) * 1.5 * hourlyRate; | |
} | |
else | |
{ | |
pay = hourlyRate * hoursWorked; | |
} | |
return pay; | |
} | |
void getRateAndHoursAndPrintPay(int person) | |
{ | |
double hourlyRate = 0; | |
double hoursWorked = 0; | |
printf("Enter the hourly rate of pay for person %d: ", person); | |
scanf("%lf", &hourlyRate); | |
printf("Enter the number of hours worked by person %d this week: ", person); | |
scanf("%lf", &hoursWorked); | |
double pay = calculatePay(hourlyRate, hoursWorked); | |
printf("Person %d earned $%.2lf this week\n", person, pay); | |
} | |
int main() | |
{ | |
getRateAndHoursAndPrintPay(1); | |
getRateAndHoursAndPrintPay(2); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment