What he meant was the brace style was inconsistent. For instance in the function you have the open and close braces on their own lines, which is fine. However, for the loops and other blocks you include the braces on the same lines as the statement. Honestly, if you only have one statement in a loop or similar structure you are almost better off not using braces at all, but simply indenting the statement.
I don't know why, but many coders seem to think that it's better to cram as much code into as few lines as possible and show little consideration to readability. But, the flip side is stuff like TIM pointed out. There are spots that can be condensed and made more efficient. Me, I like to add a blank line to separate multiple line of code that form logical blocks.
Here's your unit() function made a bit more readable (at least, for me. Formatting style for code is a hotly debated topic among programmers, so there's no single "right" way. But there are some ways that most people can read more easily then if you don't follow a pattern at all.)
1 2 3 4 5 6 7 8 9 10 11
|
void unit (string& temp_unit, string& loop) // I like to space parameters by a space after the comma
{
if (temp_unit=="Celsius"||temp_unit=="celsius"||temp_unit=="C"||temp_unit=="c")
temp_unit="Celsius"; //Single statements don't require braces inside loops
else if (temp_unit=="Fahrenheit"||temp_unit=="fahrenheit"||temp_unit=="f"||temp_unit=="F")
temp_unit="Fahrenheit";
else if (temp_unit=="Kelvin"||temp_unit=="kelvin"||temp_unit=="K"||temp_unit=="k")
temp_unit="Kelvin";
else
loop="2";
}
|
Now, in my programs, I might go a step further and separate each of the loops by a blank line, but it's not really necessary. This should be more then enough to ease the eye strain for most folks. :)
One other thing that you could try is to make separate function for each conversion type. It would cut down on the amount of code inside each function. Then you simply call the proper function using a switch with the temp_unit. This would cut down on all the if/else statements all over. I also agree it might be better to use single char for the user input and a toupper or tolower function. This kind of input would be less prone to user error because, well, let's face it, how many folks can type Fahrenheit of Celsius properly even when it's RIGHT IN FRONT OF THEM ON THE SCREEN? Ok, I admit, I even had to look for fahrenheit. :)