Re: Looping to the start?
Try a while loop.
something like...
inputvalue = something
while(inputvalue != Z){
inputvalue = userinput
if(inputvalue = a){
}else if(inputvalue = b){
}else if(inputvalue = c){
}else if....
}
you get the idea.
}
Re: Looping to the start?
Quote:
Originally Posted by
XTOTHEL
Try a while loop.
something like...
To translate: Perform two cascaded layers one layer of loop to check for the Z-input condition, then process the actual meaningful input given, now knowing that it is not Z.
edit: brainfart. I thought it was more complicated than it is, now my explanation seems more confusing than this problem itself is.
Re: Looping to the start?
Alright, so I messed around with the while loop idea.
It seems like the loop works fine until you input the letter. Then it keeps repeating on itself...
This is what happened when I added while:
http://dl.dropbox.com/u/1395149/results1.png
This is what happened when I placed a readline command at the end of the loop:
http://dl.dropbox.com/u/1395149/results2.png
I tried using a return command to see if that would help, but that only offered the above results as well. The break command was nice for finishing everything though.
Re: Looping to the start?
You could clear the value of the userinput inside each if?
Also remember to have the command to make the user input something INSIDE the while loop.
(Also if this is C+ why not use the Do-While? its almost the same thing iirc, but it will run at least once)
Re: Looping to the start?
Ah right, I guess I should mention this is C#. Does C# have something like that?
Googled it: Looks like it does. I'll try that out.
Re: Looping to the start?
It seems that XL's code assumes a two-step process:
a. Get user's input - Z: End program; anything else: Load program.
b. Get user's input - Z: End program; Any other letter: Treat as employee's initial.
The bare minimum you need is just step b for this problem.
> "Hey yo, good day. Say, what do you want?"
> Input A [from range A, B, C, ..., Z].
> "Okay okay, hold on, Andrew, was it? Done. What do you want now?"
> Input B [from range A, B, C, ..., Z].
> "Hmmm.. Barbara from HR? Got it. What do you want now?"
> Input Z [from range A, B, C, ..., Z].
> "Aight, see ya later.
I'd suggest using a boolean exit flag, something like:
Code:
boolean done = false;
while(done != true) {
// do stuff because not done
if(user_input.equals("Z")) {
done = true; // set exit flag
}
}
Re: Looping to the start?
Update?
So I ended up figuring out what the problem was, and then felt like an idiot about it. basically it needed to look like THIS:
So the lesson for the day was don't over look simple things that should be obvious. It'll hurt even more when you do realize the problem. :f3:
Thanks to everyone that gave some advice! I hope I don't have to worry about overlooking simple things in the future.