cs50is not a standard header. So, it reduces the portability of your code.You might as well as
return 0;at the end ofmainas it is not implicit in C89 (ansi C)This part:
printf("Equals %.2f hours \n", real_time/60); hours = real_time/60;should be outside the
do...whileloop as it needs to be executed only if the user enters a valid input forreal_time.Using
doubles are better thanfloats because they have much better precision.You could inform the user that invalid input was typed when the user enters some invalid input. But I do not know what
get_floatreturns on non-number inputs. If you do, you can check for it too.The part to get input can be separated into another function to avoid repetition.
Last but not least, indent your code properly. Currently, it looks like a mess with a few extra braces lurking around here and there.
One thing you must do, is indent your code properly. Now,Putting it looks like a mess with extra braces lurking around here and there. Something like:all together, we get
#include <stdio.h>
#include <cs50.h> /* Warning! Non-standard header! */
intdouble mainget_double_input(voidconst char* prompt)
{
floatdouble clip_time;input;
floatfor(;;)
real_time; {
float pay_rate; printf("%s ", prompt);
float pay_amt;
fflush(stdout);
float hours;
input = get_double();
do if(input > 0)
{
printf("Transcription Rates\n"); break;
printf}
fputs("Clip"Invalid Time:input! "Input should be greater than 0! Try again \n", stderr);
}
clip_timereturn =input;
}
int get_floatmain(void);
{
}whiledouble clip_time;
double real_time;
double pay_rate;
double pay_amt;
double hours;
printf("Transcription Rates \n");
clip_time <== 0get_double_input("Clip Time: ");
char prompt[50];
printfsprintf(prompt, "%.2f min clip pays: ", clip_time);
pay_rate = get_floatget_double_input(prompt);
printf("So, $%.2f for the project \n", pay_rate * clip_time);
pay_amt = pay_rate * clip_time;
do
{
real_time = printfget_double_input("Time to Complete Clip (in minutes): ");
real_time = get_float();
printf("Equals %.2f hours \n", real_time/60);
hours = real_time/60;
}while(real_time <= 0);
printf("Real time spent per audio minute: %.2f \n", real_time / clip_time);
printf("Hourly pay $%.2f div by %.2f hours equals $%.2f ph \n", pay_amt, hours, pay_amt / hours);
return 0;
}
Also,Untested Code ↑
cs50is not a standard header. So, it reduces the portability of your code.You might as well as
return 0;at the end ofmainas it is not implicit in C89 (ansi C)This part:
printf("Equals %.2f hours \n", real_time/60); hours = real_time/60;should be outside the
do...whileloop as it needs to be executed only if the user enters a valid input forreal_time.Using
doubles are better thanfloats because they have much better precision.You could inform the user that invalid input was typed when the user enters some invalid input. But I do not know what
get_floatreturns on non-number inputs. If you do, you can check for it too.