Can you please help?
This is what i have.
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 37 38
|
#include <iostream>
#include <string>
#include "cstdlib"
using namespace std;
double far (double a, double c);
double cel (double b, double c);
int main()
{
double a, b, c;
char x;
cout << "Enter a 1 for celsius to fahrenheit, 2 for celsius to fahrenheit: ";
cin >> x;
cout << "Enter a temperature: ";
cin >> c;
switch (x)
{
case '1' : cout << far (a, c);
break;
case '2' : cout << cel (b, c);
break;
}
}
double far (double a, double c)
{
a = .55555 * (c - 32);
return a;
}
double cel (double b, double c)
{
b = (1.8 * c) + 32;
return b;
}
|
Last edited on
You declared a and b as parameters, but they don't have a value when you pass it as an argument.
Last edited on
The program "works" it just doesn't do the math correctly and I don't know how to fix it
It "works" correctly, just the code in line 15:
cout << "Enter a 1 for celsius to fahrenheit, 2 for celsius to fahrenheit: ";
has the wrong sentence.
And I'm thinking you're wasting variables like a and b, in line 12:
double a, b, c;
The far() and cel() routines are the wrong way round, and have too many arguments (as has already been pointed out).