How to start from beginning of the program

前端 未结 6 1733
灰色年华
灰色年华 2021-01-17 02:00

I am a very beginner in c++. i am just learning abc of this language.. i created this small program that would add:

#include 
   using namesp         


        
6条回答
  •  伪装坚强ぢ
    2021-01-17 02:06

    You can try putting the main part of your 'adding' in an endless loop. I suggest use a post condition loop, meaning one that will execute it's body at least once (then it will check the condition and so on), because you'll be wanting to add some numbers at least once.

    Example:

    do {
      // do stuff here
    } while (true) // always true condition -> makes the loop infinite
    

    So I guess you'll ask how do you stop this. You can ask the user if he wants to continue. Add this to the loop's body:

     int lock = 0;
     cout << "Do you want to continue? (0 = no, 1 = yes)" << endl;
     cin << lock;
     if (lock == 0) break; // stops the loop immeadiately
    

    You can do the same with lock being char with values 'y' or 'n'.

提交回复
热议问题