Thread: Another n00b c++ question (restarting app)

  1. #1

    Question Another n00b c++ question (restarting app)

    Hi. I've made a simple application that can calculate between meters and inches, centigrades and fahrenheit and a bunch of other things. My problem is that I've made it so the int main() thing has a menu (displayed using cout, then a cin to accept user input). When the user chooses an option, the program then uses a switch depending on which option was chosen. When the user has typed in some stuff to be calculated, the application is terminated. Is there a way to restart the application instead ?

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    By "restart" do you mean go back to the main menu? You can use a simple while loop to do this. Add a choice to your menu labeled exit. The while loop condition should check to see if the user inputted this option. If they did, then quit the program.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    I'm less than sure.... abyssphobia's Avatar
    Join Date
    Aug 2004
    Posts
    112
    well if ou put some code,not all, an esencial part,
    We can figure out

    Code:
    char op;
    do{
             your code
       blah blah blah
    cout<<"do you want more,again ??? Y/N";
    cin>>op;
    }while( op!='n');
    maybe this is what you need, Im glad if this help you!!!
    take care,
    abyss.
    Have I crossed the line?

  4. #4
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    You could just put your menu into a function

    Code:
    void Menu()
    {
    
        //+---Menu Code---+
    
    }
    
    int main()
    {
    
        Menu();    //+---Show Menu---+
        
        //+---Make choices----+
    
        //+---If you want to go again---+
        Menu();
    
        //+---ELSE quit---+
    
    }

  5. #5
    the Wizard
    Join Date
    Aug 2004
    Posts
    109
    Vicious: Well you don't know how many times the user of the program wants to try again, and therefore the while-loop is the best solution
    -//Marc Poulsen -//MipZhaP

    He sat down, he programmed, he got an error...

  6. #6
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Ah, I cant believe I did that, everything Ive been programming lately has been large projects with a main loop and I guess I just forgot.

    he could do this then...

    Code:
    int main()
    {
    
        for(;;) {
    
            Menu();
            Choice();
    
            if(Choice() == QUIT) break;
    
        }
    
        return 0;
    
    }
    Last edited by Vicious; 08-27-2004 at 01:55 PM.

  7. #7
    the Wizard
    Join Date
    Aug 2004
    Posts
    109
    Yes, sounds a lot more reasonable
    -//Marc Poulsen -//MipZhaP

    He sat down, he programmed, he got an error...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. n00b question regarding the Map Class in the STL library
    By Axegrinder#9 in forum C++ Programming
    Replies: 2
    Last Post: 12-17-2005, 09:40 PM
  2. another exercise question
    By luigi40 in forum C# Programming
    Replies: 3
    Last Post: 11-28-2005, 03:52 PM
  3. pasword app
    By GanglyLamb in forum C Programming
    Replies: 2
    Last Post: 06-07-2003, 10:28 AM
  4. MFC Dialog App Screen Refresh Question
    By Scotth10 in forum Windows Programming
    Replies: 2
    Last Post: 10-18-2002, 02:07 PM
  5. GUI App Question ??
    By aumfc in forum Windows Programming
    Replies: 9
    Last Post: 10-17-2002, 02:56 AM