Skip to main content
added 102 characters in body
Source Link
Spikatrix
  • 1k
  • 1
  • 9
  • 21
  • cs50 is not a standard header. So, it reduces the portability of your code.

  • You might as well as return 0; at the end of main as 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...while loop as it needs to be executed only if the user enters a valid input for real_time.

  • Using doubles are better than floats 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_float returns 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 ↑

  • cs50 is not a standard header. So, it reduces the portability of your code.

  • You might as well as return 0; at the end of main as 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...while loop as it needs to be executed only if the user enters a valid input for real_time.

  • Using doubles are better than floats 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_float returns on non-number inputs. If you do, you can check for it too.

One thing you must do, is indent your code properly. Now, it looks like a mess with extra braces lurking around here and there. Something like:

#include <stdio.h>
#include <cs50.h>

int main(void)
{
    float clip_time;
    float real_time;
    float pay_rate; 
    float pay_amt;
    float hours; 

    do
    {
        printf("Transcription Rates\n");
        printf("Clip Time: ");
        clip_time = get_float();

    }while(clip_time <= 0);
    
    printf("%.2f min clip pays: ", clip_time);
    pay_rate = get_float();
    
    printf("So, $%.2f for the project \n", pay_rate * clip_time);
    pay_amt = pay_rate * clip_time;
    
    do
    {
        printf("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);

}

Also,

  • cs50 is not a standard header. So, it reduces the portability of your code.

  • You might as well as return 0; at the end of main as 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...while loop as it needs to be executed only if the user enters a valid input for real_time.

  • Using doubles are better than floats 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_float returns on non-number inputs. If you do, you can check for it too.

  • cs50 is not a standard header. So, it reduces the portability of your code.

  • You might as well as return 0; at the end of main as 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...while loop as it needs to be executed only if the user enters a valid input for real_time.

  • Using doubles are better than floats 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_float returns 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.

Putting it all together, we get

#include <stdio.h>
#include <cs50.h> /* Warning! Non-standard header! */

double get_double_input(const char* prompt)
{
    double input;

    for(;;)
    {
        printf("%s ", prompt);
        fflush(stdout);
    
        input = get_double();
        if(input > 0)
        {
            break;
        }

        fputs("Invalid input! Input should be greater than 0! Try again \n", stderr);
    }

    return input;
}

int main(void)
{
    double clip_time;
    double real_time;
    double pay_rate; 
    double pay_amt;
    double hours; 

    printf("Transcription Rates \n");
    clip_time = get_double_input("Clip Time: "); 

    char prompt[50];
    sprintf(prompt, "%.2f min clip pays: ", clip_time);
    pay_rate = get_double_input(prompt);
    
    printf("So, $%.2f for the project \n", pay_rate * clip_time);
    pay_amt = pay_rate * clip_time;
    
    real_time = get_double_input("Time to Complete Clip (in minutes): ");

    printf("Equals %.2f hours \n", real_time/60);
    hours = real_time/60;

    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;
}

Untested Code ↑

added 102 characters in body
Source Link
Spikatrix
  • 1k
  • 1
  • 9
  • 21

One thing you must do, is indent your code properly. Now, it looks like a mess with extra braces lurking around here and there. Something like:

#include <stdio.h>
#include <cs50.h>

int main(void)
{
    float clip_time;
    float real_time;
    float pay_rate; 
    float pay_amt;
    float hours; 

    do
    {
        printf("Transcription Rates\n");
        printf("Clip Time: ");
        clip_time = get_float();

    }while(clip_time <= 0);
    
    printf("%.2f min clip pays: ", clip_time);
    pay_rate = get_float();
    
    printf("So, $%.2f for the project \n", pay_rate * clip_time);
    pay_amt = pay_rate * clip_time;
    
    do
    {
        printf("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);

}

Also,

  • cs50 is not a standard header. So, it reduces the portability of your code.

  • You might as well as return 0; at the end of main as 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...while loop as it needs to be executed only if the user enters a valid input for real_time.

  • Using doubles are better than floats 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_float returns on non-number inputs. If you do, you can check for it too.

One thing you must do, is indent your code properly. Now, it looks like a mess with extra braces lurking around here and there. Something like:

#include <stdio.h>
#include <cs50.h>

int main(void)
{
    float clip_time;
    float real_time;
    float pay_rate; 
    float pay_amt;
    float hours; 

    do
    {
        printf("Transcription Rates\n");
        printf("Clip Time: ");
        clip_time = get_float();

    }while(clip_time <= 0);
    
    printf("%.2f min clip pays: ", clip_time);
    pay_rate = get_float();
    
    printf("So, $%.2f for the project \n", pay_rate * clip_time);
    pay_amt = pay_rate * clip_time;
    
    do
    {
        printf("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);

}

Also,

  • cs50 is not a standard header. So, it reduces the portability of your code.

  • You might as well as return 0; at the end of main as 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...while loop as it needs to be executed only if the user enters a valid input for real_time.

  • Using doubles are better than floats because they have much better precision.

  • You could inform the user that invalid input was typed when the user enters some invalid input.

One thing you must do, is indent your code properly. Now, it looks like a mess with extra braces lurking around here and there. Something like:

#include <stdio.h>
#include <cs50.h>

int main(void)
{
    float clip_time;
    float real_time;
    float pay_rate; 
    float pay_amt;
    float hours; 

    do
    {
        printf("Transcription Rates\n");
        printf("Clip Time: ");
        clip_time = get_float();

    }while(clip_time <= 0);
    
    printf("%.2f min clip pays: ", clip_time);
    pay_rate = get_float();
    
    printf("So, $%.2f for the project \n", pay_rate * clip_time);
    pay_amt = pay_rate * clip_time;
    
    do
    {
        printf("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);

}

Also,

  • cs50 is not a standard header. So, it reduces the portability of your code.

  • You might as well as return 0; at the end of main as 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...while loop as it needs to be executed only if the user enters a valid input for real_time.

  • Using doubles are better than floats 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_float returns on non-number inputs. If you do, you can check for it too.

added 234 characters in body
Source Link
Spikatrix
  • 1k
  • 1
  • 9
  • 21

One thing you must do, is indent your code properly. Now, it looks like a mess with extra braces lurking around here and there. Something like:

#include <stdio.h>
#include <cs50.h>

int main(void)
{
    float clip_time;
    float real_time;
    float pay_rate; 
    float pay_amt;
    float hours; 

    do
    {
        printf("Transcription Rates\n");
        printf("Clip Time: ");
        clip_time = get_float();

    }while(clip_time <= 0);
    
    printf("%.2f min clip pays: ", clip_time);
    pay_rate = get_float();
    
    printf("So, $%.2f for the project \n", pay_rate * clip_time);
    pay_amt = pay_rate * clip_time;
    
    do
    {
        printf("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);

}

Also,

  • cs50 is not a standard header. So, it reduces the portability of your code.

    cs50 is not a standard header. So, it reduces the portability of your code.

  • You might as well as return 0; at the end of main as it is not implicit in C89 (ansi C)

    You might as well as return 0; at the end of main as 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...while loop as it needs to be executed only if the user enters a valid input for real_time.

  • Using doubles are better than floats because they have much better precision.

  • You could inform the user that invalid input was typed when the user enters some invalid input.

One thing you must do, is indent your code properly. Now, it looks like a mess with extra braces lurking around here and there. Something like:

#include <stdio.h>
#include <cs50.h>

int main(void)
{
    float clip_time;
    float real_time;
    float pay_rate; 
    float pay_amt;
    float hours; 

    do
    {
        printf("Transcription Rates\n");
        printf("Clip Time: ");
        clip_time = get_float();

    }while(clip_time <= 0);
    
    printf("%.2f min clip pays: ", clip_time);
    pay_rate = get_float();
    
    printf("So, $%.2f for the project \n", pay_rate * clip_time);
    pay_amt = pay_rate * clip_time;
    
    do
    {
        printf("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);

}

Also,

  • cs50 is not a standard header. So, it reduces the portability of your code.
  • You might as well as return 0; at the end of main as it is not implicit in C89 (ansi C)

One thing you must do, is indent your code properly. Now, it looks like a mess with extra braces lurking around here and there. Something like:

#include <stdio.h>
#include <cs50.h>

int main(void)
{
    float clip_time;
    float real_time;
    float pay_rate; 
    float pay_amt;
    float hours; 

    do
    {
        printf("Transcription Rates\n");
        printf("Clip Time: ");
        clip_time = get_float();

    }while(clip_time <= 0);
    
    printf("%.2f min clip pays: ", clip_time);
    pay_rate = get_float();
    
    printf("So, $%.2f for the project \n", pay_rate * clip_time);
    pay_amt = pay_rate * clip_time;
    
    do
    {
        printf("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);

}

Also,

  • cs50 is not a standard header. So, it reduces the portability of your code.

  • You might as well as return 0; at the end of main as 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...while loop as it needs to be executed only if the user enters a valid input for real_time.

  • Using doubles are better than floats because they have much better precision.

  • You could inform the user that invalid input was typed when the user enters some invalid input.

Source Link
Spikatrix
  • 1k
  • 1
  • 9
  • 21
Loading