Thread: New to programming, Need help

  1. #1
    Registered User
    Join Date
    Sep 2014
    Posts
    2

    Question New to programming, Need help

    My instructor asked me to create a conversion program for Temperature conversions, his goal was for us to learn how to use functions outside of the main function/program, otherwise this would have been easier for me I think. Lines 1-64 is my source code, the Last are the errors I receive.

    Code:
    #include <stdio.h>
    
    void celsius(void); /*The celsius function in main */
    void fahrenheit(void); /*The fahrenheit function in main*/
    double get_celsius(void); /*Gets celsius temp from user*/
    double c2f(double c); /*converts celsius to fahrenheit*/
    void printFahrenheit(double f);/*prints the finished conversion*/
    double get_fahrenheit(void);/*Gets fahrenheit from user*/
    double f2c(double f);/*converts fahrenheit to celsius*/
    void printcelsius(double c);/*prints the finished conversion to celsius*/
    
    
    int main(void) /*Main Program*/
    {
            celsius();
            fahrenheit();
            return 0;
        }
        
    void celsius(void) /*celsius call function from main*/
    {   
        get_celsius();
        c2f(double c);
        printFahrenheit(double f);
        
        }
    void fahrenheit(void) /*fahrenheit call function from main*/
    {   
        get_fahrenheit();
        f2c(double f);
        printcelsius(double c);
        
        }
    double get_celsius() /*Input for C to F conversion*/
    {   
        double c;
        printf("Enter a temperature in Celcius for conversion.\n");
        scanf("%lf", &c);
        return 0.0;
    }
    double c2f(double c) /*Formula for C to F conversion*/
    { double f; 
        f = 32+9/5*c;
        return 0.0;
        }
    void printFahrenheit(double f) /*Output for C to F conversion*/
    {   printf("Temperature is %f \n", f);
            }
    double get_fahrenheit(void) /*Input for F to C conversion*/
    {   
        double f;
        printf("Enter a temperature in Fahrenheit for conversion.\n");
        scanf("%lf", &f);
        return 0.0;
        }
    double f2c(double f) /*conversion formula from F to C*/
    {   c = (f-32)*5/9
        return 0.0;
        }
    void printcelsius(double c) /*Output for F to C conversion*/
    {
        printf("Temperature is %f \n", c);
        
        }
    
    
    
    
    when I try to compile i get these errors : clang -ansi -pedantic -Wall -Wextra -W -Wmissing-prototypes -Wstrict-prototypes -Wconversion -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wwrite-strings -Wnested-externs -fshort-enums -fno-common -Dinline= -g -DDEBUG -c "pa02.c"
    Compilation failed.
    pa02.c:27:9: error: expected expression
        c2f(double c);
            ^
    pa02.c:28:21: error: expected expression
        printFahrenheit(double f);
                        ^
    pa02.c:34:9: error: expected expression
        f2c(double f);
            ^
    pa02.c:35:18: error: expected expression
        printcelsius(double c);
                     ^
    pa02.c:61:5: error: use of undeclared identifier 'c'
    {   c = (f-32)*5/9
        ^
    5 errors generated.
    My main concern is the "expected expression" errors, any help would be appreciated I've been stuck for hours. Thank you!

  2. #2
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693
    Code:
    void fahrenheit(void) /*fahrenheit call function from main*/
    {  
        get_fahrenheit();
        f2c(double f); //calling functions means that you must omit the return type and parameter data types.
        printcelsius(double c); //same goes for here.
         
        }

  3. #3
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    These errors are because you have called the functions incorrectly:
    Code:
    pa02.c:27:9: error: expected expression
        c2f(double c);
            ^
    Code:
    pa02.c:28:21: error: expected expression
        printFahrenheit(double f);
                        ^
    Code:
    pa02.c:34:9: error: expected expression
        f2c(double f);
            ^
    Code:
    pa02.c:35:18: error: expected expression
        printcelsius(double c);
                     ^
    You need to do something more like this:
    Code:
    double celsiusInput;
    double fahrenheitOutput;
    
    celsiusInput = get_celsius();
    fahrenheitOutput = c2f(celsiusInput);
    printFahrenheit(fahrenheitOutput);
    This error is because you have declared 'f' instead of 'c':
    Code:
    pa02.c:61:5: error: use of undeclared identifier 'c'
    {   c = (f-32)*5/9
    You might also want to think about returning the value in 'c' rather than 0.0
    Code:
    double get_celsius() /*Input for C to F conversion*/
    {  
        double c;
        printf("Enter a temperature in Celcius for conversion.\n");
        scanf("%lf", &c);
        return 0.0;
    }
    Fact - Beethoven wrote his first symphony in C

  4. #4
    Registered User
    Join Date
    Sep 2014
    Posts
    2
    Quote Originally Posted by Click_here View Post
    These errors are because you have called the functions incorrectly:





    You need to do something more like this:
    Code:
    double celsiusInput;
    double fahrenheitOutput;
    
    celsiusInput = get_celsius();
    fahrenheitOutput = c2f(celsiusInput);
    printFahrenheit(fahrenheitOutput);
    This error is because you have declared 'f' instead of 'c':


    You might also want to think about returning the value in 'c' rather than 0.0
    Code:
    double get_celsius() /*Input for C to F conversion*/
    {  
        double c;
        printf("Enter a temperature in Celcius for conversion.\n");
        scanf("%lf", &c);
        return 0.0;
    }
    Thank you so much, I'll give it another shot in the morning before class. I got lost during the lesson on prototypes and functions so I blame that. I'll come back if I fail still haha

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 09-11-2012, 01:03 AM
  2. Replies: 4
    Last Post: 12-11-2011, 04:25 PM
  3. small programming job VCPP / Object Oriented Programming
    By calgonite in forum Projects and Job Recruitment
    Replies: 10
    Last Post: 01-04-2006, 11:48 PM
  4. Total newb to programming here... Question about the many programming languages. Ty!
    By tsubotakid1 in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 10-05-2003, 10:32 AM

Tags for this Thread