Solution 2 report most problems with your code and also point out code we don't understand.
We read the question but without formula nor code, it is hard to know actual formula and without any formula, the question does not lead to definitive answer.
Obviously, from the code above, you do not know that in C++,
{
and
}
are used to delimit scope. You need to learn basic syntax before trying to write code.
We you learn a language, you should have documentation near instead of trying random things and expect it to work. As you would see in the following links, when there are multiple statements in an
if
or
else
clause, you need to put them in a block statement. A block is delimited by
{
and
}
.
if-else Statement (C++)[
^]
If Statements in C++ - Cprogramming.com[
^]
Statements and flow control - C++ Tutorials[
^]
In fact, many programmer would recommend to always use accolades even when you have a single statement as it make the code somewhat easier to read and maintain (as it is less error prone).
In C++, indentation does not affect parsing but you should always have the correct indentation anyway. It make the code much easier to read (and to spot unbalanced code).
But you should really indent your code even on Code Project. In fact, people that are too lazy to indent their code do not deserve any help. So you should really be grateful that we try to help you.