This is my code for using an array to track user input into a menu switch and sending the data to a .txt outfile. Thank you to all of those who helped with this. Hope it helps someone else.
So the problem is that the switch won't work until the array is full. What I am trying to do is essentially have the switch for the menu selections work as normal while just tracking the selection in a log file in the background.
oh.
you have a loop what reads the 10 choices then uses them after that.
don't do that, read one choice and jump on into the switch.
after reading (and possibly validating) the user choice, stuff it into the next array location
eg
cin >> choice;
array[index++] = choice;
switch(choice)
{
is the crude start to doing this.
however, NOW it will go until the user quits, and the array only has a few locations. It looks like you force quit on that currently, which is fine.
I get what you're saying. But if I take it out of the loop then the output into the log file only stores the first menu option that the user selects. Is there a different operator that I should be using that would allow the program to run normally and just record the inputs that the user makes in the background until the program terminates?
Also it's not option [0] its option [o]. In hindsight that was a dumb variable choice so I'm going to change it to something less confusing.
I get what you're saying. But if I take it out of the loop then the output into the log file only stores the first menu option that the user selects. Is there a different operator that I should be using that would allow the program to run normally and just record the inputs that the user makes in the background until the program terminates?
Not really. In the end, you will have to decide in which particular order you want things to happen :-)
It is not possible that things "magically" happen all at once.
Well, in theory, you could create multiplethreads, which then will be running concurrently.
So I took what you said and changed my strategy for how to do what I was trying to do. The new code in my post is what I came up with but for some reason, the compound test at the end of the 'do...while' statement is not working and everything after that is being ignored as well. Not really sure why. Any ideas?
the compound test at the end of the 'do...while' statement is not working
It probably is working, but your condition may just not be what you had intended ;-)
I suggest you run the program in a debugger and/or add more diagnostic output to see what's going on and to pinpoint where exactly things don't go as expected. Guessing probably won't give much insight...
Got it all figured out. I needed to use the && operator in the 'do... while' function and not ||. The updated code in the post works exactly as it should.
Nice work.
If you don't mind, next time, repost the code or the changed function or even the changed line rather than edit the original. It lets people follow the conversation better.
Oh got it. Will definitely do that next time. This was my first post so still figuring things out. Also, I have not had boolean algebra before but I am going through the link you posted and it's extremely helpful. Thank you very much for both the posting advice and the link.