Need help with function prototypes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dru
    New Member
    • Sep 2006
    • 29

    Need help with function prototypes

    Im having problems with prototypes anyone good with them?
  • dru
    New Member
    • Sep 2006
    • 29

    #2
    my code is

    Code:
    #include <stdio.h>
    
    double get_input(); /* prototype to get the input from the user */
    double calculate(double); /* prototype to calculate the deggres into celsius */
    void output(double, double);    /* prototype to give the output */
    
    double get_input()
    {
    	double fahrenheit;
    	printf("Enter the degrees in Fahrenheit:");
    	scanf_s(" %lf", &fahrenheit);  /** Get's the degrees in Fahrenheit temperature from the user using a scanf statement.**/   
    	return fahrenheit;
    }
    
    double calcuate(double fahrenheit)
    {
    		double celsius;
    		return (celsius = (get_input(fahrenheit) - 32) * (5.0 / 9.0)); /*Calculates the degrees Celsius from the degrees Fahrenheit*/
    		
    }
    
    void output(double fahrenheit, double celsius)
    {	
    printf("Degrees in Fahrenheit = %3.1f \n", fahrenheit); /** Print you results to the output */
    printf("Degrees in Celsius = %3.1f \n", calculate(celsius));/** Print you results to the output */
    }
    
    int main()
    
    {
       double fahrenheit;/* temperature in degrees Fahrenheit */
       double celsius;   /* temperature in degrees Celsius */
       get_input( ); /* invokes get_input */
       calculate(); /* invokes calculate */
       output(fahrenheit, celsius);    /* invokes output */
    
      return (0);
    
    }

    Comment

    • dru
      New Member
      • Sep 2006
      • 29

      #3
      please im begging someone to help me

      Comment

      • ltgbau
        New Member
        • Sep 2006
        • 41

        #4
        Code:
        double calcuate(double fahrenheit)  {  	double celsius;  	return (celsius = ([B]get_input(fahrenheit)[/B] - 32) * (5.0 / 9.0)); /*Calculates the degrees Celsius from the degrees Fahrenheit*/    }
        you use get_input in wrong way, it has no parameter. the right way is below:
        Code:
        double calcuate(double fahrenheit)  {  	double celsius;  	return (celsius = ([B]get_input()[/B] - 32) * (5.0 / 9.0)); /*Calculates the degrees Celsius from the degrees Fahrenheit*/    }

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          Originally posted by dru
          please im begging someone to help me
          It has only been 20 minutes from your first post, you should wait 24 hours before a response like this just to give everyone the chance to wake-up and read your post. We are not all in the same time zone as you.

          Your prototypes look fine, but you are not envoking the functions correctly

          Code:
             get_input( ); /* invokes get_input */
             calculate(); /* invokes calculate */
          should be

          Code:
             fahrenheit = get_input( ); /* invokes get_input */
             celsius = calculate(fahrenheit); /* invokes calculate */

          Comment

          • dru
            New Member
            • Sep 2006
            • 29

            #6
            Error when ran:lgtbau's
            f:\documents\vi sual studio\celsius 2\celsius 2\celsius 2.c(45) : error C2198: 'calculate' : too few arguments for call

            Comment

            • dru
              New Member
              • Sep 2006
              • 29

              #7
              i apologize for that its that i have been trying to figure this out for days and its due in less than 5 hours

              but i reall apprecuiate the help

              Comment

              • dru
                New Member
                • Sep 2006
                • 29

                #8
                by the way this program is in C

                Comment

                • dru
                  New Member
                  • Sep 2006
                  • 29

                  #9
                  Error when ran Banfa's

                  f:\documents\vi sual studio\celsius 2\celsius 2\celsius 2.c(45) : warning C4700: uninitialized local variable 'fahrenheit' used
                  1>f:\documents\ visual studio\celsius 2\celsius 2\celsius 2.c(46) : warning C4700: uninitialized local variable 'celsius' used
                  1>Linking...
                  1>Celsius 2.obj : error LNK2019: unresolved external symbol _calculate referenced in function _main
                  1>F:\Documents\ Visual Studio\Celsisu2 a\Debug\Celsisu 2a.exe : fatal error LNK1120: 1 unresolved externals

                  Comment

                  • dru
                    New Member
                    • Sep 2006
                    • 29

                    #10
                    any1 got any ideas?

                    Comment

                    • dru
                      New Member
                      • Sep 2006
                      • 29

                      #11
                      New Updated Code:
                      Code:
                      #include <stdio.h>
                      
                      double get_input(); /* prototype to get the input from the user */
                      double calculate(double); /* prototype to calculate the deggres into celsius */
                      void output(double);    /* prototype to give the output */
                      
                      double get_input()
                      {
                      	double fahrenheit;
                      	printf("Enter the degrees in Fahrenheit:");
                      	scanf_s(" %lf", &fahrenheit);  /** Get's the degrees in Fahrenheit temperature from the user using a scanf statement.**/   
                      	return fahrenheit;
                      }
                      
                      double calcuate(double fahrenheit)  
                      {  	
                      	double celsius;  	
                      	return (celsius = (get_input() - 32) * (5.0 / 9.0)); /*Calculates the degrees Celsius from the degrees Fahrenheit*/    
                      }  
                      
                      void output(double celsius)
                      {	
                      printf("Degrees in Celsius = %3.1f \n", celsius);/** Print you results to the output */
                      }
                      
                      int main()
                      
                      {
                         double fahrenheit;/* temperature in degrees Fahrenheit */
                         double celsius;   /* temperature in degrees Celsius */
                         get_input(); /* invokes get_input */
                         calculate(); /* invokes calculate */
                         output(celsius);    /* invokes output */
                      
                        return(0);
                      
                      }
                      Errors coming up after compiled:

                      >------ Build started: Project: Celsisu2a, Configuration: Debug Win32 ------
                      >Compiling...
                      >Celsius 2.c
                      >f:\documents\v isual studio\celsius 2\celsius 2\celsius 2.c(43) : error C2198: 'calculate' : too few arguments for call
                      >Build log was saved at "file://f:\Documents\Vi sual Studio\Celsisu2 a\Celsisu2a\Deb ug\BuildLog.htm "
                      >Celsisu2a - 1 error(s), 0 warning(s)
                      ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

                      Comment

                      • ltgbau
                        New Member
                        • Sep 2006
                        • 41

                        #12
                        double calcuate(double fahrenheit)
                        this function doesn't need the fahrenheit parameter
                        so it should be
                        double calcuate()
                        try it.
                        onother error: the exact function name is calculate

                        Comment

                        • dru
                          New Member
                          • Sep 2006
                          • 29

                          #13
                          Well I didn't try taht yet but I did try this and it works one problem though on my compiler for some reason it asks for degrees in farenheit 3 times before working any ideas here the code:

                          Code:
                          /********************************************************************************
                           Name:Andrew Lichenstein        Program:Celsius2.c
                          
                           SS#:0287                       Total Points:50
                          
                           Due:09/13/2006
                          
                           Description: This programs allows you to enter a temperature in Fahrenheit
                                        and this program will convert it into Celsius by using prototypes.
                          *********************************************************************************/
                          
                          #include <stdio.h>
                          
                          double get_input(); /* prototype to get the input from the user */
                          double calculate(double); /* prototype to calculate the deggres into celsius */
                          void output(double);    /* prototype to give the output */
                          
                          double get_input()
                          {
                             double fahrenheit;
                             printf("Enter the degrees in Fahrenheit:");
                             scanf_s("%lf", &fahrenheit);  /** Get's the degrees in Fahrenheit temperature from the user using a scanf statement.**/      return fahrenheit;
                          }
                          
                          double calculate(double fahrenheit)  
                          {        
                          	double celsius;         
                          	return (celsius = (get_input() - 32) * (5.0 / 9.0)); /*Calculates the degrees Celsius from the degrees Fahrenheit*/    
                          } 
                          
                          void output(double celsius)
                          {    printf("Degrees in Celsius = %3.1f \n", calculate(celsius));/** Print you results to the output */
                          }
                          
                          int main()
                          
                          {
                            double fahrenheit = 0;/* temperature in degrees Fahrenheit */
                            double celsius = 0;   /* temperature in degrees Celsius */
                            get_input(); /* invokes get_input */
                            calculate(fahrenheit); /* invokes calculate */
                            output(celsius);    /* invokes output */
                          
                           return 0 ;
                          
                          }
                          I will try what you said while i wait

                          Comment

                          • ltgbau
                            New Member
                            • Sep 2006
                            • 41

                            #14
                            1st call in get_input
                            2nd call in calculate
                            3rd call in output
                            the problem is in the logic that you want the program to run, not in code
                            Code:
                            double calculate(double fahrenheit)    {          	double celsius;           	return (celsius = (get_input() - 32) * (5.0 / 9.0)); /*Calculates the degrees Celsius from the degrees Fahrenheit*/      }
                            replace get_input() by fahrenheit

                            Comment

                            • dru
                              New Member
                              • Sep 2006
                              • 29

                              #15
                              why does it make it ask input 3 times?

                              Comment

                              Working...