unqualified-id before 'while'; unqualified-id at end of input; and expected '}' at end of input

C:\Users\bue\Documents\ATOM FILES\stock_tracking1_with_simpleMenu_appended_TRY4.cpp:1110:2: error: expected unqualified-id before 'while'
while gameOn != false {
^~~~~
C:\Users\bue\Documents\ATOM FILES\stock_tracking1_with_simpleMenu_appended_TRY4.cpp:1246:1: error: expected '}' at end of input
}
^
C:\Users\bue\Documents\ATOM FILES\stock_tracking1_with_simpleMenu_appended_TRY4.cpp:1106:1: error: expected unqualified-id at end of input
}
^
I have been stuck here for a few weeks. Anyone available to point me in the correct direction so I can solve these errors? Not sure how to get the code to you.
> while gameOn != false
At a guess
while ( gameOn != false )

If that doesn't work, and you want a better answer, you need to post your code.
The problem is before while statement. For example, you might have this:
1
2
int
while gameOn != false {

The compiler expects a variable name after int.
or this:
int oops(); //; is an error
{
while (nonsense);
}
I am an 81-year-old-hobbyist; I love coding in c++. My code is too long for posting. I have therefore included those portions of my code wherein errors occur. I hope you can help. It'd be a major breakthrough for me. I am using ATOM. If you need the entire code, please advise me how I may send it to you. Thank you one and all for trying so far. I truly appreciate this.

1095:1: error: expected unqualified-id before 'while'
while (gameOn !=false)

1
2
3
class Menu
while (gameOn !=false) //line 1095 where error occurs
{



line 1233:1: error: expected '}' at end of input
1
2
3
4
5
6
7
8
9
10
11
12
13
	}
		default:
			cout << "Not a Valid Choice. \n";
			cout << "Choose again.\n";
			cout << "";
			break;
		}

	}

	system("PAUSE");
	return 0;
}  //line 1233 where error occurs 



line 1092:1: error: expected unqualified-id at end of input
}
^
1
2
3
4
5
6
7
8
9
	}
	char const*value()
	{
		return "Value";
}  //line 1092 where error occurs

class Menu
while (gameOn !=false)
{
What is line 1 of your first excerpt supposed to be doing? You just have a "class Menu" thing floating there, seemingly with no relation to your while loop. Delete the "class Menu" line, it surely isn't correct.

For your last two errors, you will find the error once you look through your code and make sure everything is indented correctly.
As in, make sure every { (opening brace) is closed with a } (closing brace), and indent for each level of { } that you use.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
while (stuff)
{
	if (something)
	{

	}

	switch (stuff)
	{
		case 1:
			stuff;
			break;
		case 2:
			stuff;
			break;
	}
}


(Whether the { is on its own line or not is not as important; the key is to be consistent in style and indentation.)

Two closing braces following each other at the same level of indentation should never happen:
1
2
3
4
	}
 
		// stuff
	} 

Last edited on
A DEBUGGING TIP: Isolate the problem and run that as a unit.

You're wasting your time writing and debugging a single slab comprising 1233+ lines of code and handling the debugging process this way.

At some stage the error must have started. Go back to that point and write a separate unit, get that right and then weave that back into the master version.

Show us the test unit if you have errors with that and need help.
@OP,
I am happy to look at your code.
If you enable PM I can give you my email.
Thank you againtry and Thomas1965 for your encouraging, positive responses. My plan is to to follow the logical debugging procedures suggested by againtry. I'll carefully work through this. If I get hopelessly stuck, I will contact you Thomas1965 and eventually get the entire code to you. Please have good days all.
My plan is to to follow the logical debugging procedures suggested by againtry.

@ABUE. I'm glad to read that Thomas1965 has helped you to solve your immediate problem.

I'm also glad you haven't treated my suggestion as a demotivator.

If you add (almost) a single line and then immediately compile/run so you can virtually guarantee what has caused the error/impasse. Tear that out as a unit and the challenge of debugging are often that much easier - at least sometimes.

Time marches on ;)
Cheers.
> } //line 1233 where error occurs
Does this mean you have a single function called main() that is over 1000 lines long?

> If you need the entire code, please advise me how I may send it to you.
https://pastebin.com allows posts up to half a megabyte.
@Thomas1965,
I have been working on my unqualified-id before 'while'
while (bool gameOn != false) {
error again. Hours and hours.
I have created a struct ABUE on line 45.
I have (I think) called this struct from within the int main(void).
If possible, may I send the entire code to you?
If this is solved I'll be jumping for joy, believe me.
My email is bue@gci.net
 
while (bool gameOn != false)


This is trying to define variable gameOn as type bool within the while condition and then test for not false. You can't define a variable in a while statement. Do you mean:

 
while (gameOn != false)


or even:

 
while (gameOn == true)

Last edited on
or just while (gameOn)

however the error message is not pointing to that «unqualified-id before 'while'»
$ dict before
     1. In front of; preceding in space; ahead of; as, to stand
        before the fire; before the house.

look at the previous line

> You can't define a variable in a while statement.
yes, we can https://en.cppreference.com/w/cpp/language/while
If condition is a declaration such as T t = x, the declared variable is only in scope in the body of the loop, and is destroyed and recreated on every iteration
I expressed myself as too sweeping a generalisation. The given example is:

1
2
3
4
5
6
7
const char cstr[] = "Hello";
	int k = 0;

	while (char c = cstr[k++])
		std::cout << c;

	std::cout << '\n';


Here c is defined within the condition clause and its potential initialisation value tested for true/false (non-zero/zero) before the assignment. This conforms to the T t = x situation with the condition test being whether x is true or false.

What I was clumsily referring to was something like:

1
2
3
4
5
6
7
const char cstr[] = "Hello";
int k = 0;

while (char c = cstr[k++] != 'l')
	std::cout << c;

std::cout << '\n';


which compiles but does not display what is expected. The reason is that != has a higher precedence than = and so is executed first. Hence c can only have the values true or false (1 or 0) and if true displays the char with ASCII value of 1. This is equivalent to:

1
2
3
4
5
6
7
onst char cstr[] = "Hello";
int k = 0;

while (char c = (cstr[k++] != 'l'))
	std::cout << c;

std::cout << '\n';



You might think that doing as below would solve this - but it doesn't

1
2
3
4
5
6
7
const char cstr[] = "Hello";
int k = 0;

while ((char c = cstr[k++]) != 'l')
	std::cout << c;

std::cout << '\n';


As you now get compile errors.

It was this situation to which I made the erroneous generalisation that you can't define a variable in while statement. I should have said that 'you can't define a variable in a while statement and provide a specific condition test'. :)
Last edited on
hello seeplus
thank you for your kind reply.
I have sent Thomas1965 the entire code via email.
I see various answers, all of which make my head spin.
Hopefully, Thomas1965 can clearly solve this for me.
Please have a good day.
hello all.
Thomas got my program running.
I am almost there. I have one of those "cannot call a member function, so you need an object" errors. Looking into that now.
class foo
{
int function();
...
};

foo::function(); //error, no object
foo x;
x.function(); //ok, tied to object x.
progressing! thanks jonnin
cleaning the program up now, then I'll add the graph.
have a good day, all. You're all amazing.
Topic archived. No new replies allowed.