You should add at least 5 comments to the code provided. Be sure to recompile an
ID: 3775166 • Letter: Y
Question
You should add at least 5 comments to the code provided. Be sure to recompile and test the code after you have added your comments to make sure you have not introduced any syntax errors.
I have entered my comments below, please let me know if they make sense and are correct...
//You should add at least 5 comments to the code provided. Be sure to recompile and test the code after you have added your comments to make sure you have not introduced any syntax errors.
#include <stdio.h>
#define DAYS 7
int main(void) {
printf("Enter hourly wage: "); //program asks user to enter their hourly wage
float wage;
scanf("%f", &wage); //User enters wage into program
printf("Enter hours for each day in the week: ");
int i = 0;
float hours[DAYS];
for(i = 0; i < DAYS; i++) {
printf("Day %d: ", i + 1);
scanf("%f", &hours[i]);
}
float totalHours = 0;
for(i = 0; i < DAYS; i++) {
totalHours += hours[i];
}
//Calculates overtime wages
float grossPay = 0;
if(totalHours > 40) {
float overtimeHours = totalHours - 40;
grossPay += overtimeHours * wage * 1.5;
grossPay += wage * 40;
}
else {
grossPay = totalHours * wage; //calculates regular wages
}
printf("Gross pay: $%.2f", grossPay); //displays gross pays to user.
return 0;
}
Explanation / Answer
#include <stdio.h>
#define DAYS 7 //define DAYS=7
int main(void) {
printf("Enter hourly wage: "); //program asks user to enter their hourly wage
float wage;
scanf("%f", &wage); //User enters wage into program
printf("Enter hours for each day in the week: "); //program asks user to enter hours for each day in the week
int i = 0;
float hours[DAYS]; //declaring array to store hours for each day in the week
for(i = 0; i < DAYS; i++) {
printf("Day %d: ", i + 1);
scanf("%f", &hours[i]); //User enters hours into program
}
float totalHours = 0;
//calculating total hours
for(i = 0; i < DAYS; i++) {
totalHours += hours[i];
}
//Calculates overtime wages
float grossPay = 0;
if(totalHours > 40) {
float overtimeHours = totalHours - 40;
grossPay += overtimeHours * wage * 1.5;
grossPay += wage * 40;
}
else {
grossPay = totalHours * wage; //calculates regular wages
}
printf("Gross pay: $%.2f", grossPay); //displays gross pays to user.
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.