I hope the following helps, and doesn't confuse you. My apologies if it does.
1) The semicolon ends a statement. The syntax of C++ does not have a problem with you putting more than one semicolon on a line. However, it can cause confusion for the developer (you). Things may make more sense if you put each statement on its own line.
2) The "if" statement reads in a condition. If the condition is true, it runs the very next statement. If you want it to run more than one statement, place the statements in curly braces. As an example, see below. All of line 2 will print only if the remainder is zero. Line 3 will always print.
1 2 3
|
if (remainder == 0)
cout << "This will print if the remainder is equal to zero" << endl;
cout << "This will always print." << endl;
|
If you put line 3 at the end of line 2, as it is below, the program will run exactly the same.
1 2
|
if (remainder == 0)
cout << "This will print if the remainder is equal to zero" << endl; cout << "This will always print." << endl;
|
If you want more than one statement to run if a condition is met, surround the lines with curly braces. See below...
1 2 3 4 5
|
if (remainder == 0) {
cout << "This will print if the remainder is equal to zero." << endl;
cout << "This will also print if the remainder is equal to zero." << endl;
}
cout << "This will always print." << endl;
|
Run through your code and place each statement on its own line. Put curly braces around lines you wish to run together. Re-post your new code here, surrounding your code with [co de] and [/co de] so that we get the pretty blue boxes. Let us know how it goes.