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.
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
{
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:
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.
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.
@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
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:
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
constchar 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
constchar 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
constchar 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'. :)
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.