In: Computer Science
Design and write a function to calculate a person’s
pay for a variable number of hours worked.
● Create a constant called HOURLY_RATE set to 24.95
● To Consider - should this be local to the function or
global?
● Ask the user to enter their number of hours worked (do this
inside the function). Remember to always use meaningful variable
names for variables!
● Then calculate and return their total pay
Add code to main which will call this function and display their
pay.
Float
SOURCE CODE:
*Please follow the comments to better understand the code.
**Please look at the Screenshot below and use this code to copy-paste.
***The code in the below screenshot is neatly
indented for better understanding.
#include <stdio.h>
//Global Variable
#define HOURLY_RATE 24.95
float calculate_pay(float hours_worked)
{
//Multiply the values and return the result
return hours_worked * HOURLY_RATE;
}
int main()
{
float hours_worked, pay;
//Input the data
printf("Enter the number of hours worked: ");
scanf("%f",&hours_worked);
//Call the function
pay= calculate_pay(hours_worked);
//print the result
printf("Pay = %f",pay);
return 0;
}
==============
SCREENSHOT: