Thread: goto or not goto

  1. #1
    In The Light
    Join Date
    Oct 2001
    Posts
    598

    goto or not goto

    howdy,
    i understand that goto is to be avoided so in the following switch what is the proper way of getting back to case'y' without starting the complete switch over again?


    Code:
    switch(pick){
      case 'm':
      case 'M':
        {answer = static_cast <int> (rand())%high_range;}
        break;
      case 'y':
      case 'Y':
      enter: //<<<<--------------------------
          cout<<"Enter a number"<<endl;
          cin>>hi_range;
            if(!IsIntt (hi_range)){ //check for int
      	cout<<"Must be an integer"<<endl;
      	goto enter;} //<<<<------------------
         else
         
          high_range = atoi (hi_range);
    	cout<<"hi: "<<hi_range<<"high: "<<high_range<<endl;   
     break;
      };
    thanks
    M.R.

  2. #2
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    use do-while loops
    -

  3. #3
    Unregistered
    Guest
    Code:
    switch(pick){
      case 'm':
      case 'M':
        {answer = static_cast <int> (rand())%high_range;}
        break;
      case 'y':
      case 'Y':
          int flag = 1;
          while(flag == 1)
          {
             cout<<"Enter a number"<<endl;
             cin>>hi_range;
             if(!IsIntt (hi_range)){ //check for int
      	cout<<"Must be an integer"<<endl;
             else
              {
                  flag = 0;
                  high_range = atoi (hi_range);
                cout<<"hi: "<<hi_range<<"high: "<<high_range<<endl; 
               } 
           } 
           break;
      };

  4. #4
    In The Light
    Join Date
    Oct 2001
    Posts
    598

    wow

    howdy,
    after i post these things and see the replies it occurs(sp) to me that i am trying to over complicate this stuff

    itld trys to remeber KISS.

    thanks all
    M.R.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 07:26 PM
  2. goto command
    By jhwebster1 in forum C Programming
    Replies: 3
    Last Post: 02-21-2006, 12:32 PM
  3. Does goto have a glitch or...?
    By Blackroot in forum C++ Programming
    Replies: 9
    Last Post: 02-18-2006, 10:40 AM
  4. helpppp
    By The Brain in forum C Programming
    Replies: 1
    Last Post: 07-27-2005, 07:05 PM
  5. Need some help with a basic tic tac toe game
    By darkshadow in forum C Programming
    Replies: 1
    Last Post: 05-12-2002, 04:21 PM