473,396 Members | 1,915 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Need help with function prototypes

29
Im having problems with prototypes anyone good with them?
Sep 29 '06 #1
24 3441
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,065 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

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

Similar topics

5
by: titan0111 | last post by:
#include<iostream> #include<iomanip> #include<cstring> #include<fstream> using namespace std; class snowfall { private: int ft;
8
by: Robert | last post by:
Hi, I can use "with" like this: function MyObject(message) { this.message = message; } function _MyObject_speak() {
0
by: Norm Wong | last post by:
If anyone is interested in using db2uext2 with Cygwin gcc compiler on Windows, I've modified the IBM provided sample with the attached file. There are two main modifications. The mkdir command...
9
by: Grumble | last post by:
Hello everyone, I've come across some strange code. Here it is, stripped down: int main(void) { int *foo; int *bar(); foo = bar(0); return 0;
12
by: TTroy | last post by:
For function definitions (not declarations/prototypes), is it necessary to put void in the emptry braces if the function is to receive no parameters? Does this turn any error checking off or cause...
7
by: junky_fellow | last post by:
Can a function have two different prototypes ? If not , then how can main() have two different prototypes ? int main(void) and int main argc(int argc, char *argv) I mean to say, if I declare...
9
by: wizwx | last post by:
what does the following mean? int func2(); According to C++, it surely means func2 is a function that takes no argument and returns an integer. But what about in C? Does it have the same...
32
by: lcdgoncalves | last post by:
Hi everyone Is there a real need to use keyword static with functions, if we simply don't declare their prototypes in .h file? Many textbooks avoid to discuss this matter and/or discuss only...
73
by: Steph Barklay | last post by:
Hi, I'm currently taking a data structures course in C, and my teacher said that function prototypes are not allowed in any of our code. He also said that no professional programmers use function...
29
by: Ravishankar S | last post by:
Dear C Experts, While prepating a content for a C course,I made section on function prototypes. Could you kindly provide me your comments on its correctness. Thank you ! Q12: What is the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.