Thread: Ifs and Whiles

  1. #1
    Registered User
    Join Date
    Jan 2017
    Posts
    2

    Ifs and Whiles

    Hey everyone!

    I have this table that gives a few values with the basic conversion from Fahrenheit to Celsius. Can someone please add code that asks the user for a starting value, ending value and the increment that the table increases by?

    So the start (first fahrenheit value), end (last fahrenheit value), increment (Amount it goes up by each time).

    Thanks a toooon guys!

    Code:
    #include <stdio.h>
    
    
    
    
    int main()
    {
                   float fahrenheit;
                   float Celcius;
    
    
                   printf("Input Fahrenheit");
                   scanf("%f", &fahrenheit);
    
    
    
    
                   float degF;
                   degF=0;
    
    
    
    
                   while (degF <= 100)
                   {
                                   if (degF > 98.6)
                                   {
    printf("%6.2f degrees F =             %6.2f degrees C\n", 98.6, (98.6 - 32.0) * 5.0/9.0);
                                   }
    printf("%6.2f degrees F =             %6.2f degrees C\n", degF, (degF - 32.0) * 5.0/9.0);
                                   degF = degF + 10;
                   }
                   return 0;
    }
    Last edited by Dkman; 01-02-2017 at 04:06 PM. Reason: add tags

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    It looks like the loop came from here, with just a variable rename.

    The OP contributed scanf to the fahrenheit variable has no consequence to the running of the code.

    @OP, if you're planning to get through the course with "found" code and forum begging, you're just wasting your time (and ours).
    This stuff gets much harder real quick, and you're already falling behind.

    You don't become a chef by visiting restaurants, reading menus and sampling the food. You have to get into the kitchen and make all the mistakes of burning the toast, letting pans boil over and setting the oven on fire before you can master the craft.

    Hint:
    degF = fahrenheit;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Tags for this Thread