TempVert Function

Just having a little trouble. I get an error when it compiles. Here's my code:

// Begin program

#include <iostream>
using namespace std;

double tempvert(double, char); //<----Probably here is why I can't get it to run
// because I'm using a double and char in the the same prototype?

int main ()
{
double tempVal, final;
char tempLetter;

cout << "Enter a temperature: ";
cin >> tempVal;
cout << "Enter a letter (f for fahrenheit): ";
cin >> tempLetter;

final = tempvert(tempVal, tempLetter);

cout << "The temperature conversion is " << final << endl;

return 0;
}

double tempvert(double x, char y) //<----Here as well.
{
double result;

if (y == 'f')
result = (5.0/9.0) * (x - 32.0);
else
result = (9.0/5.0) * x + 32.0;

return result;
}

// End Program

Any help would be appreciated. Thanks!
Last edited on
In the future... tell us what the actual problem is.

"I'm having a little trouble" is not descriptive.

"I get the following error when I try to compile: ..." is much better.


As for your problem -- your function prototype and your function body don't match:

1
2
3
4
5
6
double tempvert(double, char);  // <- returns a double, lowercase v

void tempVert(double x, char y)  // <- returns a void, capital V
{
//...
}


You need to change it so they match.

probably you want to use the prototype version. So change your function body to this:

 
double tempvert(double x, char y) // <- return double, lowercase v 
Topic archived. No new replies allowed.