Results 1 to 8 of 8
  1. Default Looping to the start?


    Okay, so I am on my final project for the semester in programming, but I am having an issue straight from the get go, and seeing a tutor after school didn't seem to help because she didn't know what she was doing either.

    I have to build a program that will continually take in letters for employee names (The letters that will let it run are A,B, and E. It is ran on the assumption that the user makes no mistakes.) and it needs to loop back to the initial question that ask for the next letter, unless the letter Z is put in, which terminates the program. So it needs to keep looping and asking for letters until Z is put in, going from the bottom of the list to the top.

    I have made a quick code to try to test multiple ways to work this, however, it will only show all three if they go in the order they are scripted in. If you jump to the second employee, you cannot get to the first. *Note: The code isn't finished, so a lot of the variables won't make sense. This is only meant to display their names.*

    Spoiler


    I do not believe the teacher went over these kinds of loops with us. What we learned SEEMED pretty basic. And my tutor seemed stumped as well.

    If my description was confusing, I have this screencap of the visual logic flow chart he gave to us. You can see it here.

    He's able to loop the program over and over again until he presses Z, and I don't know how to replicate this effect in Visual Studio.

  2. Default 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.


    }

  3. Default Re: Looping to the start?


    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.

  4. Default 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:



    This is what happened when I placed a readline command at the end of the loop:



    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.

  5. Certified Pimento Bi Male
    IGN: xxxxFenixR
    Server: Bera
    Level: Mix
    Job: Severals
    Guild: None
    Alliance: Nada
    Farm: Wut?
    venezuela

    Default 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)

  6. Default 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.

  7. Default 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
        }
    }

  8. Default 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:

    Spoiler


    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.

    Thanks to everyone that gave some advice! I hope I don't have to worry about overlooking simple things in the future.

  9.  

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •