Im having problems with prototypes anyone good with them?
Need help with function prototypes
Collapse
X
-
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); }
-
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*/ }
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
-
Originally posted by druplease im begging someone to help me
Your prototypes look fine, but you are not envoking the functions correctly
Code:get_input( ); /* invokes get_input */ calculate(); /* invokes calculate */
Code:fahrenheit = get_input( ); /* invokes get_input */ celsius = calculate(fahrenheit); /* invokes calculate */
Comment
-
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 externalsComment
-
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); }
>------ 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
-
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 ; }
Comment
-
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*/ }
Comment
Comment