how do you...

This is a discussion on how do you... within the C++ Programming forums, part of the General Programming Boards category; restart the program...

  1. #1
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942

    how do you...

    restart the program

  2. #2
    samurai warrior nextus's Avatar
    Join Date
    Nov 2001
    Posts
    196
    like exit the program and it re-execute it or...just go back to the beginning of the code?
    nextus, the samurai warrior

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    162
    restart as in?.....

  4. #4
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    rexecute the code from the top without quitting

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You design your code well, so you don't need to restart. This is rather vague, to match your question

    Or you could get it to spawn a new copy itself.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Code:
    while(something)
    {
       YourCode();
    }
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  7. #7
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    I want the program to restart once it reaches the end. Like a calculator.

  8. #8
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    > restart once it reaches the end.

    You want it to restart every time?

    Code:
    while(1)
    {
       stuff
    }

  9. #9
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    LOOP

    The topic you need to study is called "loops". There are for-loops, while-loops, do-while loops... So, you can also look-up "for", "do", and "while".

    [EDIT]
    LOOPING and CONDITIONAL EXECUTION/ CONDITIOAL BRANCHING are the two features that make programming valuable. (IMHO)
    Last edited by DougDbug; 03-20-2003 at 10:39 AM.

  10. #10
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117
    Here is an example of loop I used on a console program I made a while ago.

    Code:
    int main()
    {
          program();
          return 0;
    }
    
    
    void program()
    {
    	while (y != 'e')
    	{
    		menu();
    		cin >> y;
    		ans(y);
    		
    	}
    }
    
    
    void menu() // display menu
    {
    	cout <<endl<< "What would you like to do?" << '\n'<<endl;
          	cout << "[I] Input a date?" << endl;
    	cout << "[O] Output a date?" << endl;
    	cout << "[D] Delete a date?" << endl;
    	cout << "[E] Exit?" << endl << endl;
    }
    
    
    void ans(char y) // handles answers to menu
    {
    	switch (y)
    	{
    		case 'i':
    			input();
    			break;
    		case 'o' :
    			output();
    			break;
    		case 'd' :
    			delet();
    			break;
    		case 'e' :
    			break;
    	}
    }
    Thise is not the full code but I think its a good example on how you could do it for a calculator..
    Luigi


    // I use Xcode 1.1 && CodeWarrior 8.3
    // When on Mac Os X 10.3.2

    // I use Microsoft Visual C++ 6.0
    // When on windows XP

  11. #11
    Registered User Diamonds's Avatar
    Join Date
    Oct 2002
    Posts
    68

    the evil way

    i'm going to get really yelled at for this

    void main() {
    10 //beinging


    //end
    goto 10;
    }


    muhahaha

  12. #12
    The Pantless Man CheesyMoo's Avatar
    Join Date
    Jan 2003
    Posts
    262
    It physically hurts me.
    If you ever need a hug, just ask.

  13. #13
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >i'm going to get really yelled at for this
    So why did you suggest it? void main is very wrong and there are more elegant solutions than goto in this situation.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21