Hello HelpMeBro,
It was late for me and I realized later that there were a few things I did not mention.
When it comes to floating point prefer to use "double" over "float". I considered the possibility that what you are working from may be old when "float" was the normal choice.
The code demonstrates how a few blank lines make a big difference in readability.
Even though this is a small program a good variable name can still make a big difference.
When it comes to things like "if" statements it is a good practice to use {}s even for 1 line. In this example you will need to add to your if statements. Also there is nothing wrong with the way you first presented you if/else if statements and C++ does not have an "else if" as part of the language, but
is what most people tend to use and what I have most often seen.
In a reply to
Ganado you said:
But there were 12 problems to practice. Those all problems will be solved by if statement.
|
This is something that you should have mentioned at the very beginning so those responding will have a better idea what you have to do.
Your original code works very well at finding the lowest number and printing it out. But after you find the lowest number you still need to check the remaining 2 to decide which 1 to print first. So each of your original if/else if statements will have more choices to deal with until you have printed out all 3 numbers.
Then you may want to consider what would happen if any 2 of the 3 numbers is the same.
It would look something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
if (num1 < num2 && num1 < num3)
{
cout << num1 << '\n';
// num1 is the lowest, so between num2 and num3 determine which is lowest. Then print what is left. Same concept for the other 2.
if (num2 < num3)
{
std::cout << num2 << '\n' << num3 << '\n';
}
else
{
std::cout << num3 << '\n' << num2 << '\n';
}
}
else if (num2 < num1 && num2 < num3)
|
Andy