MandrewP 60 Junior Poster in Training

Do NOT Follow this advice!!!!1) We do NOT - repeat NOT - recommend bad coding practices here!2) We do NOT - repeat NOT - write the code for people!3)

Ooooh boy! Here we go again, confusion run wild!

I thought I was perfectly clear in condemning the use of goto:label statements in regular program code. Here is what I said:

<< Now, I used a goto statement to make your program work. However, goto is bad bad programming practice. It's EVIL! LOL - not really evil, after all, it is a valid programming statement. However, for reasons to be discussed later, if you use goto in your program like I did, it will be condemned by academia forever. >>

<< it will be condemned by academia forever >>..... so she will submit goto's to her instructor??? I think not! I just assumed that by my condemnation of goto:label it would NOT be thought I was RECOMMENDING the practice! Yeah, I guess assumption killed the cat!

And I never said that I wrote the code, it was simply her OWN code that I added a goto statement to, and moved one line down. I let her copy and paste it to make it easier to avoid typos. This is the equivalent of a code snippet. And adding the goto statement was NOT solving the problem for her, it was only used to show and suggest program logic to solve her problem - she was to see the …

MandrewP 60 Junior Poster in Training

I was trying to make it so that the user can opt to re-search or go back to the main menu, but it doesn't work...

OK, here is what I'm going to do: Below is code that will do what you want, just copy and paste it into your compiler. However, you will still have to figure some things out.
But first, you need to understand how the goto statement works - it's easy. Goto is a statement that causes program flow to jump to a label, like so:

do_again:          //This is a label and ends with a ":".
cout "I'm in a goto loop!";
goto do_again;

You can put a label (the label can be called anything you want, just end it with ":") anywhere in your program and then you can jump to that location with "goto label".

Now, I used a goto statement to make your program work. However, goto is bad bad programming practice. It's EVIL! LOL - not really evil, after all, it is a valid programming statement. However, for reasons to be discussed later, if you use goto in your program like I did, it will be condemned by academia forever. If you use goto at all, it should only be in the privacy of your own home - lol.

But I used it here just to show you the idea of how this could work. Once you see the logic of the program, then you HAVE to re-code it …

WaltP commented: NO NO NO NO!!!! -4
MandrewP 60 Junior Poster in Training

Ah, well just to make it more annoying for us students, it's been set that we HAVE to have the student ID as a string... otherwise, it would be a whole world easier to code it! And "escape a"? So if I code in \a, where would it escape to? Sorry to keep annoying you with questions, by the way... Oh, and we haven't learn how to use goto yet so... I don't know what that does...

OK, then the way Walt posted would be sensible, since if stdIDInput wasn't found, because of an out of range number, then just handle that.

You know how to use the escape n (\n) for a newline, right. Well, just use escape a (\a) in your cout statement to make a beep, just like in my example.

A goto statement just says to goto some label, like k: in the example, and is just a simple form of loop which is rarely used because the while or for loops are better structured. I just used it as a quick and dirty loop : ).

MandrewP 60 Junior Poster in Training

OK, first let's concentrate on the out of range input, then after that you can do the additional ID input.

The main problem here is that you need to test for high or low input ranges, but you are dealing with strings. The string "15000000" has no relation at all to the value of 15 million. It's just a string of symbols, no different than "Hello World". So you are going to have to change the varible stdIDInput to type int instead of type string.

Once you do that, then stdIDInput is an integer value that you can simply test for high or low values with an if statement, and loop back around with an error message and to re-enter the stdIDInput.

switch(option)
    {
      case 1:

    k:     cout << "Please type in the student ID number\nof the student you want
                    to search,\nthen press enter.\n";
           cin >> stdIDInput;
           if(stdIDInput < 15000000 || stdIDInput > 17000010)
           goto k;

Of course, you don't need to use an actual goto statement, but you get the idea. Also, just in case you didn't know, you can beep the beeper whenever an input in out of range, just add escape a in your cout statement. For example:

cout "\aYou entered a number too high";

Then you will get a beep.

WaltP commented: Quite worthless information... -4