PLease help!! IM LOST

This is a discussion on PLease help!! IM LOST within the C Programming forums, part of the General Programming Boards category; Hello everyone, i am new here. I am taking a class inro to programing in C. I have to do ...

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    8

    Unhappy PLease help!! IM LOST

    Hello everyone, i am new here.

    I am taking a class inro to programing in C. I have to do this program, and i have no idea what it asks me to do. I am very lost in the class there fore i do not understand what i have to do. I am not asking anyone to do the assignment for me, but to put it in simple words that i can understand. The assignments is as follows.

    In this assignment you will implement a program called celsius2.c (see sample_celsius2.c file below) that uses several functions, get_input, output, and determine_c. You must use get_input to read the Fahrenheit degrees and return the value that was read to a variable in main. Then you will call determine_c with the value returned from get_input as an actual argument, and return the value you calculated for degrees Celsius. Then you will pass this value to the function output to print the value calculated for degrees Celsius. You will invoke all the functions from the main program.


    ANy help will be greatly appreciated. Thank you all.

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Well, I guess there are a few things you need to know to write this program. You need to understand some programming concepts, such as functions. You need to know how to pass variables between functions, and indeed how to read numbers from the user in the first place.

    You also need to know the algorithm (formula, whatever) to convert Fahrenheit into Celsius.

    I'd start with a simple program to read in a number and print it out. Then convert the number into Celsius before printing it out. Then you could separate it into functions. Or you could do it the other way around and create the functions right off the bat.

    I guess the first step would be reading about functions, if you're not very familiar with C.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Jun 2008
    Posts
    8
    Yea i mean, i know like the simple stuff, printf , scanf, double, int, all that simple stuff. I also know how to write the formula. We already did the simple program that converts Fahrenheit to Celsius, now this is the second, we are supposed to use prototypes.

    The thing that throws me off is the get_input, output, calculate_c. are those actual functions. or user defined stuff?

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    They're used-defined. You make up those functions.

    Here's a short tutorial about them: http://www.cprogramming.com/tutorial/c/lesson4.html

    Here's an example of a function . . . .
    Code:
    #include <stdio.h>
    
    /* this is the prototype of a function */
    int square(int x);
    
    int main() {
        int r = square(3);
        printf("3 squared is &#37;i\n", r);
        return 0;
    }
    
    int square(int x) {
        int s = x * x;
        return s;
    }
    Basically, a function has several parts.
    Code:
    <return-type> <function-name>(<parameters>) {
        <code>
        <return-statement>
    }
    The return type is what the caller of the function will receive. For example, if this was int, the caller could go
    Code:
    int x = function();
    The value returned from a function is specified by a return statement, like so:
    Code:
    int function(void) {
        return 3;
    }
    If the return type is "void", the function doesn't return anything and you use use
    Code:
    return;
    or leave out the return statement entirely.

    The parameters are a comma-separated list of variables that are passed into the function -- data from the original caller function. For example:
    Code:
    #include <stdio.h>
    
    void add(int x, int y);
    
    int main() {
        add(3, 4);
        return 0;
    }
    
    void add(int x, int y) {
        printf("%i\n", x + y);
    }
    If a function doesn't pass any parameters, you can use "void" for the parameter list.

    Anyway -- for a much clearer explanation, check out the nearest C book . . . .
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    Jun 2008
    Posts
    8
    Hey thanks alot man, i really appreciate it. This will help me alot.

  6. #6
    Registered User
    Join Date
    Jun 2008
    Posts
    8
    hello again i have read he turorials, and some of my book. Just when i thinki get it , when it comes to the actuall coding i loose it al over again. This is ike the "skeleton of the program".. if anyone can take a look at it and help me out. ***Im not asking anyone to do the programfor me, just a little further assitace** Thank you!

    Code:
    #include <stdio.h>
    
    /*********Prototype go here******
    
     double get_input();
    
    double calculate_c(double);
    
    void output(double);
    
     ******************************/
    
    /**********implement function here**************
    
    double get_input( )
    
    {
    
      /** get the degrees Fahrenheit temperature from the user   using a scanf statement.
    
              Prompt the user with something like this:
    
     
    
                  Enter the degrees Fahrenheit:               **/
    
    }
    
    double calcuate_c(double fahrenheit)
    
    {
    
      /** calculate the degrees Celsius from the degrees Fahrenheit using the following formula:
    
              celsius = 5/9 ( Fahrenheit –32).                                                                             **/
    
    }
    
    void output(double celcuis)
    
    {
    
     /** Print you results to the screen in the following format :
    
                    Degrees Celsius = what was computed in the program                                    **/
    
     
    
    }
    
    ***************************************/
    
    int main()
    
    {
    
        /************Declare variables here  **********/
    
     
    
       double Fahrenheit;              /* temperature in degrees Fahrenheit     */
    
     
    
    /***invoke get_input  ***/
    
     /**invoke calculate_c ***/
    
      
    
    /** Print you results to the screen in the following format :
    
                    Degrees Fahrenheit  = whatever the user entered
    
                                                         **/
    
     /***invoke output  ****/
    
      return 0;
    
    }

  7. #7
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Code:
    #include <stdio.h>
    
    /*********Prototype go here******
    
     double get_input();
    
    double calculate_c(double);
    
    void output(double);
    
     ******************************/
    
    /**********implement function here**************
    
    double get_input( )
    
    {
    
      /** Declare a variable of type double to hold the input from the user **/
      /** Use printf to output "Enter the degrees Fahrenheit:"**/
      /** Then use scanf to get the input and save it to the variable **/
      /** Return the variable **/
    
    }
    
    double calcuate_c(double fahrenheit)
    
    {
    
      /** Declare a variable called 'celsius' of type double **/
    
      celsius = 5/9 * ( fahrenheit –32);                                                                             
    
      /** Return celsius **/
    
    }
    
    void output(double celcius)
    
    {
    
     /** Use printf to output "Degrees Celsius =", and then the variable celsius **/
    
    }
    
    ***************************************/
    
    int main()
    
    {
    
        /************Declare variables here  **********/
    
     
    
       double Fahrenheit;              /* temperature in degrees Fahrenheit     */
    
      /** You would probably need a variable to hold the celsius value aswell? **/
    
     
    
    /***invoke get_input  ***/
    
     /**invoke calculate_c ***/
    
      
    
    / ** Again, use printf for this **/
    /** Print you results to the screen in the following format :
    
                    Degrees Fahrenheit  = whatever the user entered
    
                                                         **/
    
     /***invoke output  ****/
    
      return 0;
    
    }

    You are definetly on the right track, i've added the steps you need to complete the program. You said you knew how to use printf and scanf, so it should be a breeze from now on...

    Oh, and i've fixed some of the variable names that was in the program for you, remember, C is case-sensitive. So Celsius and celsius is not the same...
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I lost my laptop, DVD and money
    By Sang-drax in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 10-01-2004, 08:13 PM
  2. lost disk
    By Benzakhar in forum Linux Programming
    Replies: 7
    Last Post: 01-11-2004, 06:18 PM
  3. So LOST!!!
    By Drew Vance in forum C Programming
    Replies: 6
    Last Post: 04-25-2003, 06:37 PM
  4. Lost ID number
    By ripper079 in forum C++ Programming
    Replies: 13
    Last Post: 10-04-2002, 01:51 PM
  5. API, LOST... help
    By Unregistered in forum Windows Programming
    Replies: 5
    Last Post: 03-13-2002, 03:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21