Last visit was: It is currently Thu Mar 28, 2024 11:50 am


All times are UTC-05:00




Post new topic Reply to topic  [3 posts ] 
    Author Message
     Post subject:Help with C++ Program
    PostPosted:Mon Jan 28, 2008 9:35 pm 
    User avatar
     

    Joined:Sat Mar 11, 2006 8:28 am
    Posts:365
    Location:Canada
    Right now I am trying to make a program that uses a switch/case but i need to have a goto back to the top.

    The problem is that the goto loop doesn't goto loop, i think its because it is in the switch/case, can someone help me resolve this, its important. (If the goto loop cant do it, suggest an alternative please)
    Code:
    void location() { int choice = 0; int secondchoice = 0; loop: switch (choice) case 0: { cout << "What would you like to do?"; cout << "1.Dosomthing"; cout << "2.Dosomthing else"; cin >> secondchoice; switch (seconchoice) case 1:{ //do something goto loop; break; } case 2:{ //do something else goto loop; break; } break; } }
    Thanks, Darkknight512

    _________________
    Best file compression around: "DEL *.*" = 100% compression
    "640K ought to be enough for anybody." - Bill Gates, 1981


    Top
    Offline  
     Post subject:Re: Help with C++ Program
    PostPosted:Tue Jan 29, 2008 11:28 am 
     

    Joined:Thu Jul 06, 2006 2:34 pm
    Posts:16
    secondchoice is typed wrongly in the second switch. With that corrected it works fine (with visual express 2005 atleast). You can do that also without gotos with continue:
    Code:
    void location() { int choice = 0; int secondchoice = 0; while(1){ switch (choice) case 0: { cout << "What would you like to do?\n"; cout << "1.Dosomthing"; cout << "2.Dosomthing else"; cin >> secondchoice; switch (secondchoice) case 1:{ //do something continue; } case 2:{ //do something else continue; } } } }


    Top
    Offline  
     Post subject:Re: Help with C++ Program
    PostPosted:Tue Jan 29, 2008 4:28 pm 
    User avatar
     

    Joined:Sat Mar 11, 2006 8:28 am
    Posts:365
    Location:Canada
    Well I only quickly typed that out not to release my actual code but I'll try the continue;.

    Edit: I added the continue but it dosen't seem to go back to the while(1).

    Edit 2: Never mind it was an error else where in my code, (did a int choice = 0, instead of choice = 0)
    Thanks a lot it worked :)

    _________________
    Best file compression around: "DEL *.*" = 100% compression
    "640K ought to be enough for anybody." - Bill Gates, 1981


    Top
    Offline  
    Display posts from previous: Sort by 
    Post new topic Reply to topic

      All times are UTC-05:00


      Who is online

      Users browsing this forum: No registered users and 15 guests


      You cannot post new topics in this forum
      You cannot reply to topics in this forum
      You cannot edit your posts in this forum
      You cannot delete your posts in this forum
      You cannot post attachments in this forum

      Search for:
      Jump to:  
      cron
      Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
      Theme created by Miah with assistance from hyprnova