My program is incomplete but should be executable. It won't link an else to an if statement even though everything between them is within brackets. And when i replace the else with if, it runs lines of statements that are false.
#include <iostream>
usingnamespace std;
int main()
{
int iplayer = 1;
int ia = 3;
int iaa = 3;
int ialoop = 1;
int ib = 5;
int ic = 7;
int x;
int y;
int z;
int looplines = 1;
int removeloop = 1;
{
while (ia > 0)
{cout << "|";
ia = ia - 1;}
cout << endl;
while (ib > 0)
{cout << "|";
ib = ib - 1;}
cout << endl;
while (ic > 0)
{cout << "|";
ic = ic - 1;}
while (looplines > 0)
{
cout << endl;
cout << "Which row would you like to remove lines fromn? (1, 2, or 3)";
cin >> x;
if (x = 1);
{
while (ialoop = 1)
{
cout << "How many lines would you like to remove from row 1?";
cout << endl;
cin >> y;
if (iaa >= y);
{
if (y > 0)
{
iaa = iaa - y;
cout << "line A has " << iaa << " line(s) remaining";
ialoop = ialoop - 1;
}
else (y < 0);
cout << "invalid number of lines1";
cout << endl;
}
else (y > iaa);
cout << "invalid number of lines2";
cout << endl;
}
}
}
}
cin >> z;
return 0;
}
else (y > iaa) // <---Dont Put SemiColons on If/else statments
{ //<---You Need Brackets if your doint 2 or more operations
cout << "invalid number of lines2";
cout << endl;
}
To reiterate, you don't need / can't have parenthetical statements with else -- only with if. So if you want them you need else+if -- but he doesn't need them in this case because his else conditions are the exact opposite of his if's.
1 2 3 4 5
else (y > iaa) // this makes no sense and might not even compile
else if(y > iaa) // this makes sense, but the if is unnecessary because the preceeding if will
// ensure it's always true
----
else // you can get by in this instance with just else. You only need else/if if you have
// another condition
Also I just noticed this:
while (ialoop = 1)
That is an infinite loop. You probably meant ialoop == 1. Note that = is not the same as ==