So I'm an absolute beginner writing my first program. It's a simple one which converts Celsius to Fahrenheit and visa versa. I want the input to be something like 32F, 0C, 212F and a 456G to check for error. The problem is, I don't know how to input a letter AND a number, and I don't know how to send it to the function convert to get it to check for "F" or "C".
This is what I have so far
convert
Code:
int convert(double n, char a) //Creating a function to convert degrees which takes in a number and letter
{
if (a == 'F' || 'f') //Check if fahrenheit
{
n = (n - 32)/1.8; //Convert to Celsius
a = 'C'; //Change "F" to "C"
return(n, a); //Return new number and new letter
};
if (a == 'C' || 'c') //Check if Celsius
{
n = (n * 1.8) + 32; //Convert to Fahrenheit
a = 'F'; //Change "C" to "F"
return(n, a); //Return new number and new letter
};
cout << "That isn't a Celsius or Fahrenheit measure\n\n" << endl;
}
int main
Code:
int main()
{
double x;
char y;
cout << "Please enter in a temperature in Fahrenheit (F) or Celsius (C)\n" << endl;
cin >> x >> y;
cout << "\nThat's " << convert(x, y) << " degrees\n\n";
Help?