Thread: Equiv. int functions(way behind)

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    13

    Question Equiv. int functions(way behind)

    this is just one of three codes i've been working on for three days and this is the closest i've gotten but having problems can you help?

    the result op should be:
    celsius fahrenheit
    0.0 32.0
    " "
    " "
    implementing the following int functions
    celsius 0 --> 100
    fahrenheit 32 --> 212
    chart format = tabular, min lines while op is readable & neat


    --->DO I need all this?<---
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <ctype.h>
    #include <string.h>
    #define CONVERSION_FACTOR (100.0 / 180.0)

    int main (void)
    {
    float celsius,fahrenheit;

    double F = fahrenheit, C = celsius;

    for (F < 32; F > 212)
    { F = C;
    }
    printf(" %s%13d\n", "Celsius", "Fahrenheit");
    scanf("%f", &F, &C);
    C = CONVERSION_FACTOR * (F - 32);

    system("pause")
    return 0;
    }

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    4
    okay. I see that you have F=fahrenheit and C=celsius as type double. and then you have in your prinf statement %s and %d. So what is it. You are going to want to declare F and C as a char if you plan on using %s. You don't need all those lib functions either. Get rid of some. I would get rid of ctype.h, and stdlib.h. I don't think you need math.h unless you are going to use pow. But I am unsure of that. Maybe now you can look at my question and help me out. Maybe?

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    375
    Given your program, you need to only include <stdio.h> and <stdlib.h>.

    A for loop takes three arguments, not two. The arguments F < 32; F > 212 makes no sense at all in the context of the program. What are you trying to accomplish with this? Setting F=C doesn't accomplish anything. It might help to write out the formula in English, then in English "code", then in C.

    Your printf statement is printing the string, "Celsius" and then trying to convert the string (string = string of characters) "Fahrenheit" into a number which doesn't work very well. I bet you meant to replace that first %s with %f (and the second %13d with %f as well) and replace "Celsius" with C and "Fahrenheit" with the variable F.

    The scanf() is wrong and doens't seem to have a point. Are you trying to get a number to convert? Is this number going to be in Fehrenheit (I presume by looking ahead to the next line)? OK, get rid of your whole loop thing before all together. Get rid of:
    double F = fahrenheit, C = celsius;
    completely. Add a final printf() to tell the user the conversion. Here's your code modified:

    Code:
    #include <stdlib.h>
    #include <stdio.h> 
    #define CONVERSION_FACTOR (100.0 / 180.0) 
    
    int main (void) 
    { 
     // Variable declarations.
     float C, F; 
    
     // Print instructions.
     printf("\aPlease enter a Fahrenheit number to be converted:  "); 
     // Scan in the number.
     scanf("%f", &F); 
    
     // Do the conversion.
     C = CONVERSION_FACTOR * (F - 32); 
    
     // Print out the conversion.
     printf("\n\n%f in Celsius is: %f\n\n", F, C);
    
     // Pause for user input to quit.
     system("pause"); 
     // Exit program.
     return 0; 
    }
    Hope that makes more sense to you.
    Allegro precompiled Installer for Dev-C++, MSVC, and Borland: http://galileo.spaceports.com/~springs/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. memory leak
    By aruna1 in forum C++ Programming
    Replies: 3
    Last Post: 08-17-2008, 10:28 PM
  2. Replies: 26
    Last Post: 11-30-2007, 03:51 AM
  3. getting a headache
    By sreetvert83 in forum C++ Programming
    Replies: 41
    Last Post: 09-30-2005, 05:20 AM
  4. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  5. Quack! It doesn't work! >.<
    By *Michelle* in forum C++ Programming
    Replies: 8
    Last Post: 03-02-2003, 12:26 AM