Jul 12, 2012 at 2:24am Jul 12, 2012 at 2:24am UTC
Here's a bit of code I can't seem to get to work for the life of me.
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
#include <iostream>
int main()
{
double converter;
char cf;
while (true )
{
while (std::cin)
{
std::cout << "Enter the value you want to convert." << std::endl;
std::cin >> converter >> cf;
if (cf == 'F' || cf == 'f' )
{
std::cout << "New value: " << ((cf-32)*5)/9 << std::endl << std::endl;
}
else if (cf == 'C' || cf == 'c' )
{
std::cout << "New value: " << ((cf*9)/5)+32 << std::endl << std::endl;
}
else
{
std::cout << "Error." << std::endl << std::endl;
}
}
std::cin.clear();
}
}
Entering 0 C should get it to convert to Fahrenheit (and everything should evaluate to double, not int,) so I'm obviously doing something wrong. But what?
Last edited on Jul 12, 2012 at 2:24am Jul 12, 2012 at 2:24am UTC
Jul 12, 2012 at 2:38am Jul 12, 2012 at 2:38am UTC
This is a minor error, heh. You formula's are using "cf", the character, instead of "converter", the value of the temperature. Try adjusting that and see if it works.
Jul 12, 2012 at 2:41am Jul 12, 2012 at 2:41am UTC
I think that here
std::cout << "New value: " << ((cf-32)*5)/9 << std::endl << std::endl;
and here
std::cout << "New value: " << ((cf*9)/5)+32 << std::endl << std::endl;
you should use converter instead of cf :)