Hello ajohns2,
When it comes to naming a variable choosing a name that describes what it is or what it does is better than just coming up with something.
In your code you define "float choice;", but never use it. The variable "input1" would work better as just "input", but look at what you are doing. You are asking the user to make a
choice between "c" or "f". Using "choice" is a better choice for the variable name.
You have defined "celsius", no offense, but it is not spelled correctly, and "fahrenheit" as "floats". This may work, but could be a problem later. These days "double" is the preferred floating point type as it has greater precision than a 'float". Also when you put something like "5.0" or "9.0" in your formula these numbers are considered "doubles" by the IDE and compiler. Putting a "double", with up to 20 decimal places, into a "float" with 15 decimal places could cause a data loss when it drops the extra decimal places.
When writing the if/else if statements consider this. Your are asking for either "c" or "f" from the user, so what you could do is:
1 2 3 4
|
if(std::tolower(choice) == 'c")
// code for choice "c"
else
// Code for choice "f"
|
Since you only have two choices a simple if/else will work. This will also cout out the redudant code that you have.
Instead of using "input2" this is where you can use "celsius" and "fahrenheit" and it makes the code easier to read and understand.
Give it some thought and see what you come up with.
Hope that helps,
Andy