468,512 Members | 1,354 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,512 developers. It's quick & easy.

Need help with function prototypes

29
Im having problems with prototypes anyone good with them?
Sep 29 '06 #1
24 3222
dru
29
my code is

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. double get_input(); /* prototype to get the input from the user */
  4. double calculate(double); /* prototype to calculate the deggres into celsius */
  5. void output(double, double);    /* prototype to give the output */
  6.  
  7. double get_input()
  8. {
  9.     double fahrenheit;
  10.     printf("Enter the degrees in Fahrenheit:");
  11.     scanf_s(" %lf", &fahrenheit);  /** Get's the degrees in Fahrenheit temperature from the user using a scanf statement.**/   
  12.     return fahrenheit;
  13. }
  14.  
  15. double calcuate(double fahrenheit)
  16. {
  17.         double celsius;
  18.         return (celsius = (get_input(fahrenheit) - 32) * (5.0 / 9.0)); /*Calculates the degrees Celsius from the degrees Fahrenheit*/
  19.  
  20. }
  21.  
  22. void output(double fahrenheit, double celsius)
  23. {    
  24. printf("Degrees in Fahrenheit = %3.1f \n", fahrenheit); /** Print you results to the output */
  25. printf("Degrees in Celsius = %3.1f \n", calculate(celsius));/** Print you results to the output */
  26. }
  27.  
  28. int main()
  29.  
  30. {
  31.    double fahrenheit;/* temperature in degrees Fahrenheit */
  32.    double celsius;   /* temperature in degrees Celsius */
  33.    get_input( ); /* invokes get_input */
  34.    calculate(); /* invokes calculate */
  35.    output(fahrenheit, celsius);    /* invokes output */
  36.  
  37.   return (0);
  38.  
  39. }
  40.  
  41.  
Sep 29 '06 #2
dru
29
please im begging someone to help me
Sep 29 '06 #3
ltgbau
41
Expand|Select|Wrap|Line Numbers
  1. double calcuate(double fahrenheit)  {      double celsius;      return (celsius = (get_input(fahrenheit) - 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:
Expand|Select|Wrap|Line Numbers
  1. double calcuate(double fahrenheit)  {      double celsius;      return (celsius = (get_input() - 32) * (5.0 / 9.0)); /*Calculates the degrees Celsius from the degrees Fahrenheit*/    }  
Sep 29 '06 #4
Banfa
9,056 Expert Mod 8TB
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

Expand|Select|Wrap|Line Numbers
  1.    get_input( ); /* invokes get_input */
  2.    calculate(); /* invokes calculate */
  3.  
should be

Expand|Select|Wrap|Line Numbers
  1.    fahrenheit = get_input( ); /* invokes get_input */
  2.    celsius = calculate(fahrenheit); /* invokes calculate */
  3.  
Sep 29 '06 #5
dru
29
Error when ran:lgtbau's
f:\documents\visual studio\celsius 2\celsius 2\celsius 2.c(45) : error C2198: 'calculate' : too few arguments for call
Sep 29 '06 #6
dru
29
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
Sep 29 '06 #7
dru
29
by the way this program is in C
Sep 29 '06 #8
dru
29
Error when ran Banfa's

f:\documents\visual 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\Celsisu2a\Debug\Celsisu2a.exe : fatal error LNK1120: 1 unresolved externals
Sep 29 '06 #9
dru
29
any1 got any ideas?
Sep 29 '06 #10
dru
29
New Updated Code:
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. double get_input(); /* prototype to get the input from the user */
  4. double calculate(double); /* prototype to calculate the deggres into celsius */
  5. void output(double);    /* prototype to give the output */
  6.  
  7. double get_input()
  8. {
  9.     double fahrenheit;
  10.     printf("Enter the degrees in Fahrenheit:");
  11.     scanf_s(" %lf", &fahrenheit);  /** Get's the degrees in Fahrenheit temperature from the user using a scanf statement.**/   
  12.     return fahrenheit;
  13. }
  14.  
  15. double calcuate(double fahrenheit)  
  16. {      
  17.     double celsius;      
  18.     return (celsius = (get_input() - 32) * (5.0 / 9.0)); /*Calculates the degrees Celsius from the degrees Fahrenheit*/    
  19. }  
  20.  
  21. void output(double celsius)
  22. {    
  23. printf("Degrees in Celsius = %3.1f \n", celsius);/** Print you results to the output */
  24. }
  25.  
  26. int main()
  27.  
  28. {
  29.    double fahrenheit;/* temperature in degrees Fahrenheit */
  30.    double celsius;   /* temperature in degrees Celsius */
  31.    get_input(); /* invokes get_input */
  32.    calculate(); /* invokes calculate */
  33.    output(celsius);    /* invokes output */
  34.  
  35.   return(0);
  36.  
  37. }
  38.  
Errors coming up after compiled:

>------ Build started: Project: Celsisu2a, Configuration: Debug Win32 ------
>Compiling...
>Celsius 2.c
>f:\documents\visual 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\Visual Studio\Celsisu2a\Celsisu2a\Debug\BuildLog.htm"
>Celsisu2a - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Sep 29 '06 #11
ltgbau
41
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
Sep 29 '06 #12
dru
29
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:

Expand|Select|Wrap|Line Numbers
  1. /********************************************************************************
  2.  Name:Andrew Lichenstein        Program:Celsius2.c
  3.  
  4.  SS#:0287                       Total Points:50
  5.  
  6.  Due:09/13/2006
  7.  
  8.  Description: This programs allows you to enter a temperature in Fahrenheit
  9.               and this program will convert it into Celsius by using prototypes.
  10. *********************************************************************************/
  11.  
  12. #include <stdio.h>
  13.  
  14. double get_input(); /* prototype to get the input from the user */
  15. double calculate(double); /* prototype to calculate the deggres into celsius */
  16. void output(double);    /* prototype to give the output */
  17.  
  18. double get_input()
  19. {
  20.    double fahrenheit;
  21.    printf("Enter the degrees in Fahrenheit:");
  22.    scanf_s("%lf", &fahrenheit);  /** Get's the degrees in Fahrenheit temperature from the user using a scanf statement.**/      return fahrenheit;
  23. }
  24.  
  25. double calculate(double fahrenheit)  
  26. {        
  27.     double celsius;         
  28.     return (celsius = (get_input() - 32) * (5.0 / 9.0)); /*Calculates the degrees Celsius from the degrees Fahrenheit*/    
  29.  
  30. void output(double celsius)
  31. {    printf("Degrees in Celsius = %3.1f \n", calculate(celsius));/** Print you results to the output */
  32. }
  33.  
  34. int main()
  35.  
  36. {
  37.   double fahrenheit = 0;/* temperature in degrees Fahrenheit */
  38.   double celsius = 0;   /* temperature in degrees Celsius */
  39.   get_input(); /* invokes get_input */
  40.   calculate(fahrenheit); /* invokes calculate */
  41.   output(celsius);    /* invokes output */
  42.  
  43.  return 0 ;
  44.  
  45.  
I will try what you said while i wait
Sep 29 '06 #13
ltgbau
41
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
Expand|Select|Wrap|Line Numbers
  1. 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
Sep 29 '06 #14
dru
29
why does it make it ask input 3 times?
Sep 29 '06 #15
dru
29
when ran like that i get this error in my compiler

1>------ Build started: Project: Celsisu2a, Configuration: Debug Win32 ------
1>Compiling...
1>Celsius 2.c
1>f:\documents\visual studio\celsius 2\celsius 2\celsius 2.c(43) : error C2198: 'calculate' : too few arguments for call
1>Build log was saved at "file://f:\Documents\Visual Studio\Celsisu2a\Celsisu2a\Debug\BuildLog.htm"
1>Celsisu2a - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Sep 29 '06 #16
ltgbau
41
post your code and i correct it for you :)
Sep 29 '06 #17
dru
29
awesome

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. double get_input(); /* prototype to get the input from the user */
  4. double calculate(); /* prototype to calculate the deggres into celsius */
  5. void output(double);    /* prototype to give the output */
  6.  
  7. double get_input()
  8. {
  9.    double fahrenheit;
  10.    printf("Enter the degrees in Fahrenheit:");
  11.    scanf_s(" %lf", &fahrenheit);  /** Get's the degrees in Fahrenheit temperature from the user using a scanf statement.**/
  12.    return fahrenheit;
  13. }
  14.  
  15. double calculate(double fahrenheit)    
  16. {              
  17.     double celsius;               
  18.     return (celsius = (get_input() - 32) * (5.0 / 9.0)); /*Calculates the degrees Celsius from the degrees Fahrenheit*/      
  19.  
  20. void output(double celsius)
  21. {   
  22.     printf("Degrees in Celsius = %3.1f \n", calculate(celsius));/** Print you results to the output */
  23. }
  24.  
  25. int main()
  26.  
  27. {
  28.   double fahrenheit = 0;/* temperature in degrees Fahrenheit */
  29.   double celsius = 0;   /* temperature in degrees Celsius */
  30.   get_input(); /* invokes get_input */
  31.   calculate(); /* invokes calculate */
  32.   output(celsius);    /* invokes output */
  33.  
  34.  return 0 ;
  35.  
  36.  
Sep 29 '06 #18
ltgbau
41
tested :))

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. double get_input(); /* prototype to get the input from the user */
  4. double calculate(double fahrenheit); /* prototype to calculate the deggres into celsius */
  5. void output(double fahrenheit);    /* prototype to give the output */
  6.  
  7. double get_input()
  8. {
  9.     double fahrenheit;
  10.     printf("Enter the degrees in Fahrenheit:");
  11.     scanf_s(" %lf", &fahrenheit);  /** Get's the degrees in Fahrenheit temperature from the user using a scanf statement.**/
  12.     return fahrenheit;
  13. }
  14.  
  15. double calculate(double fahrenheit)    
  16. {              
  17.     return ((fahrenheit - 32) * (5.0 / 9.0)); /*Calculates the degrees Celsius from the degrees Fahrenheit*/      
  18.  
  19. void output(double fahrenheit)
  20. {   
  21.     printf("Degrees in Celsius = %3.1f \n", calculate(fahrenheit));/** Print you results to the output */
  22. }
  23.  
  24. int main()
  25.  
  26. {
  27.   double fahrenheit = 0;/* temperature in degrees Fahrenheit */
  28.   fahrenheit=get_input(); /* invokes get_input */
  29.   output(fahrenheit);    /* invokes output */
  30.  
  31.  return 0 ;
  32.  
Sep 29 '06 #19
dru
29
nice!!!!

If you have time a haev a few questions
Sep 29 '06 #20
ltgbau
41
ha ha
it's 12:37 now in my location
and i'm having lunch now.
you can ask me later :)
Sep 29 '06 #21
dru
29
ok thankyou
141 am here cya
Sep 29 '06 #22
vermarajeev
180 100+
any1 got any ideas?

Expand|Select|Wrap|Line Numbers
  1. double calcuate(double fahrenheit)
Make this as

Expand|Select|Wrap|Line Numbers
  1. double calculate(double fahrenheit)
{
Sep 29 '06 #23
how do you wire a c++ program that contains pre-defined and user-defined functions for a distance, radius, and area?
May 9 '07 #24
Ganon11
3,652 Expert 2GB
how do you wire a c++ program that contains pre-defined and user-defined functions for a distance, radius, and area?
Please ask your question in its own thread, with more explanation than this.
May 9 '07 #25

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by Robert | last post: by
reply views Thread by Norm Wong | last post: by
9 posts views Thread by Grumble | last post: by
7 posts views Thread by junky_fellow | last post: by
9 posts views Thread by wizwx | last post: by
73 posts views Thread by Steph Barklay | last post: by
29 posts views Thread by Ravishankar S | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.