Basic C++, just started this course in school... So I'm very limited.
What I'm at doing is, below I have a variable named inputTemp, which is the product of a char, F = Fahrenheit, C = Celsius and K = Kelvin... I want to be specific when asking the user for more information, such as degrees. So when I ask for degrees in F... it wont sound so kinda funny.
I know I can write "Enter unit of temp that you want converted using (F)ahrenheit, (C)elsius, and (K)elvin" , just to specificfy which characters the program is looking for...but assume the user already knows about F, C and K.
Basically I want that cout statement to say if the user enters f:
"Enter how many units in Fahrenheit: "
or enters 'c'
"Enter how many units in Celsius: "
All of my code is below:
As you can see my output statement that shows the calculations I've written out Fahrenheit because I know that statement's conclusion is looking for the converted Fahrenheits degrees...
Any suggestions to this problem?
Thanks for reading my rant, I hope its clear and un-noobish... If you do understand my question but don't have an answer, but could de-noobify it some, could you help as far as my "clearly stated question"?
Thank you,
sjsn
What I'm at doing is, below I have a variable named inputTemp, which is the product of a char, F = Fahrenheit, C = Celsius and K = Kelvin... I want to be specific when asking the user for more information, such as degrees. So when I ask for degrees in F... it wont sound so kinda funny.
I know I can write "Enter unit of temp that you want converted using (F)ahrenheit, (C)elsius, and (K)elvin" , just to specificfy which characters the program is looking for...but assume the user already knows about F, C and K.
Code:
char inputTemp = ' '; cout << "\nEnter unit of temperature that you want converted: "; cin >> inputTemp; inputTemp = toupper(inputTemp); if (inputTemp != 'F' && inputTemp != 'C' && inputTemp != 'K') { cout << "\nYou have entered an invalid unit of temperature!" << endl << endl; return 0; } cout << "\nEnter how many units in " << inputTemp << " : "; cin >> degrees;
"Enter how many units in Fahrenheit: "
or enters 'c'
"Enter how many units in Celsius: "
All of my code is below:
Code:
#include <iostream> #include <string> #include <algorithm> using std::cin; using std::cout; using std::endl; using std::string; int main() { double degrees = 0.0; double convertedTemp = 0.0; char convertTemp = ' '; char inputTemp = ' '; char count = ' '; do { cout << "\nEnter unit of temperature that you want converted: "; cin >> inputTemp; inputTemp = toupper(inputTemp); if (inputTemp != 'F' && inputTemp != 'C' && inputTemp != 'K') { cout << "\nYou have entered an invalid unit of temperature!" << endl << endl; return 0; } cout << "\nEnter how many units in " << inputTemp << " : "; cin >> degrees; cout << "\nWhich unit of temperature would you like to convert " << inputTemp << " to: "; cin >> convertTemp; convertTemp = toupper(convertTemp); if (convertTemp != 'F' && convertTemp != 'C' && convertTemp != 'K') { cout << "\nYou have entered an invalid unit of temperature!" << endl << endl; return 0; } if (inputTemp == 'F' && convertTemp == 'C') { convertedTemp = (5.0)/9.0 * (degrees - 32) ; cout << "\n\n" << degrees << " in degrees Fahrenheit is " << convertedTemp << " in degrees Celsius. " << endl << endl; } else if (inputTemp == 'F' && convertTemp == 'K') { convertedTemp = (5.0)/9.0 * (degrees - 32) + 273.15 ; cout << "\n\n" << degrees << " in degrees Fahrenheit is " << convertedTemp << " in degrees Kelvin. " << endl << endl; } else if (inputTemp == 'C' && convertTemp == 'F') { convertedTemp = (9.0)/5.0 * degrees + 32 ; cout << "\n\n" << degrees << " in degrees Celsius is " << convertedTemp << " in degrees Fharenheit. " << endl << endl; } else if (inputTemp == 'C' && convertTemp == 'K') { convertedTemp = degrees + 273.15 ; cout << "\n\n" << degrees << " in degrees Celsius is " << convertedTemp << " in degrees Kelvin. " << endl << endl; } else if (inputTemp == 'K' && convertTemp == 'C') { convertedTemp = degrees - 273.15 ; cout << "\n\n" << degrees << " in degrees Kelvin is " << convertedTemp << " in degrees Celsius. " << endl << endl; } else if (inputTemp == 'K' && convertTemp == 'F') { convertedTemp = ((degrees-273.15)*1.8)+32 ; cout << "\n\n" << degrees << " in degrees Kelvin is " << convertedTemp << " in degrees Fahrenheit. " << endl << endl; } cout << "Would you like to Convert another unit of Temperature? (Y/N): "; cin >> count; count = toupper(count); }while (count == 'Y'); return 0; }
As you can see my output statement that shows the calculations I've written out Fahrenheit because I know that statement's conclusion is looking for the converted Fahrenheits degrees...
Any suggestions to this problem?
Thanks for reading my rant, I hope its clear and un-noobish... If you do understand my question but don't have an answer, but could de-noobify it some, could you help as far as my "clearly stated question"?
Thank you,
sjsn
Comment