output function dilemma...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
using namespace std;
// ConvertTemperature.cpp


int main()
{
   // prototype
   double convertTemperature(double);  // function prototype

   const int CONVERTS = 4;  // number of conversions to be made

   double fahrenheit;
   double celsius;

   for(int index = 0; index < CONVERTS; index++)
   {
      cout << "\nEnter a Fahrenheit temperature: ";
      cin  >> fahrenheit;

      //          function call
      celsius = convertTemperature(fahrenheit);

      cout << "The Celsius equivalent is "
           << celsius << endl;
   }

   cin.get();
   return 0;
}


//-------------------------------------------------------------------
// Output Function - code the convertTemperature() function below
//-------------------------------------------------------------------


The following is my output code for this program...Am I close..?

1
2
3
4
5
6
double convertTemperature (double celsius = 5.0/9.0 * (fahrenheit - 32.0));
{
return celsius;
}

I feel a little bit more confident about this one...What do you guys think>\\?
1
2
3
4
double convertTemperature (double celsius = 5.0/9.0 * (fahrenheit - 32.0));
{
return celsius;
}

In a function declaration or definition, what goes in the parentheses after the function name is a simple argument list. You cannot have calculations inside (except when calling the function).
Also, there is a semi-colon at the end, which cuts off the declaration from the function body.

Try rearranging thing like this:
1
2
3
4
double convertTemperature (double fahrenheit)
{    //Note how I didn't even need to declare a Celsius variable
    return 5.0/9.0 * (fahrenheit - 32.0);
}


If you want to understand more about functions, I recommend you read either of these two pages (or both):
-http://www.cplusplus.com/doc/tutorial/functions/
-http://www.cprogramming.com/tutorial/lesson4.html

It seems you're having quite a bit of trouble with the function syntax.
the second page you sent me was very useful thank you Daleth,...C++ just hasn't been my cup of tea.../: it sucks when your a networker and they make you take a damn class like this that doesnt mix with your major. But I guess it will help in becoming more of a all-round IT person...thnkx again..!
Topic archived. No new replies allowed.