continuing program until ready to stop

This is a discussion on continuing program until ready to stop within the C++ Programming forums, part of the General Programming Boards category; How wouldI get my program to continue unti I'm ready to quit? Would I use a while statement? Could someone ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    41

    Exclamation continuing program until ready to stop

    How wouldI get my program to continue unti I'm ready to quit? Would I use a while statement? Could someone give me an example of how to continue my program using y or discontinue using n.

    #include <iostream>

    using std::cout;
    using std::cin;
    using std::endl;

    int main ()

    {


    int a, b, c;
    int num1, num2, num3, num4, num5, num6;


    cout << "Welcome!\n";
    cout << "Enter three unique digits (0 through 9)." << endl;

    cout << "Enter digit 1: ";
    cin >> a;

    cout << "Enter digit 2: ";
    cin >> b;

    cout << "Enter dight 3: ";
    cin >> c;

    num1= a*100 + b*10 +c;
    num2= b*100 + a*10 +c;
    num3= c*100 + a + b*10;
    num4= c*10 + a + b*100;
    num5= a*100 + b + c*10;
    num6= a*10 + b + c*100;

    cout << "The six new numbers: "<< endl;
    cout << num1 << endl;
    cout << num2 << endl;
    cout << num3 << endl;
    cout << num4 << endl;
    cout << num5 << endl;
    cout << num6 << endl;

    //initializing sum and adding the six unique digits
    int sum;
    sum = num1 + num2 + num3 + num4 + num5 + num6;

    cout<< "Sum of the six new numbers: " <<sum << endl;

    cout << "Would you like to run it again? (y/n) : " << endl;

    return 0; //ends program successfully

    }

  2. #2
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330

    ~

    Code:
    int main (void)
    {
    	int a, b, c;
    	int num1, num2, num3, num4, num5, num6;
            char q = 'y';
    
    	while (q == 'y' || q == 'Y') {
    		cout << "Welcome!\n";
    		cout << "Enter three unique digits (0 through 9)." << endl;
    
    		cout << "Enter digit 1: ";
    		cin >> a;
    
    		cout << "Enter digit 2: ";
    		cin >> b;
    
    		cout << "Enter dight 3: ";
    		cin >> c;
    
    		num1= a*100 + b*10 +c;
    		num2= b*100 + a*10 +c;
    		num3= c*100 + a + b*10;
    		num4= c*10 + a + b*100;
    		num5= a*100 + b + c*10;
    		num6= a*10 + b + c*100;
    
    		cout << "The six new numbers: "<< endl;
    		cout << num1 << endl;
    		cout << num2 << endl;
    		cout << num3 << endl;
    		cout << num4 << endl;
    		cout << num5 << endl;
    		cout << num6 << endl;
    
    		//initializing sum and adding the six unique digits
    		int sum;
    		sum = num1 + num2 + num3 + num4 + num5 + num6;
    
    		cout<< "Sum of the six new numbers: " <<sum << endl;
    
    		cout << "Would you like to run it again? (y/n) : " << endl;
                      cin >> q;
    	}
    
    	return 0; //ends program successfully
    }
    "He who makes a beast of himself, gets rid of the pain of being a man." Dr. Johnson

  3. #3
    Funniest man in this seat minesweeper's Avatar
    Join Date
    Mar 2002
    Posts
    801
    Code:
    #include <iostream>
    
    using std::cout;
    using std::cin;
    using std::endl;
    
    int main ()
    
    {
    
    
    int a, b, c;
    int num1, num2, num3, num4, num5, num6;
    char choice;
    
    do
    {
    cout << "Welcome!\n";
    cout << "Enter three unique digits (0 through 9)." << endl;
    
    cout << "Enter digit 1: ";
    cin >> a;
    
    cout << "Enter digit 2: ";
    cin >> b;
    
    cout << "Enter dight 3: ";
    cin >> c;
    
    num1= a*100 + b*10 +c;
    num2= b*100 + a*10 +c;
    num3= c*100 + a + b*10;
    num4= c*10 + a + b*100;
    num5= a*100 + b + c*10;
    num6= a*10 + b + c*100;
    
    cout << "The six new numbers: "<< endl;
    cout << num1 << endl;
    cout << num2 << endl;
    cout << num3 << endl;
    cout << num4 << endl;
    cout << num5 << endl;
    cout << num6 << endl;
    
    //initializing sum and adding the six unique digits
    int sum;
    sum = num1 + num2 + num3 + num4 + num5 + num6;
    
    cout<< "Sum of the six new numbers: " <<sum << endl;
    
    cout << "Would you like to run it again? (y/n) : " << endl;
    cin>>choice;
    }
    while (choice == 'y' || choice == 'Y');
    
    return 0; //ends program successfully
    
    }
    I added this:

    Code:
    char choice;
    
    do
    {
    at the start, and

    this:
    Code:
    cin>>choice;
    }
    while (choice == 'y' || choice == 'Y');
    at the end.

    EDIT: beaten
    Last edited by minesweeper; 01-19-2003 at 07:21 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 03:30 PM
  2. Replies: 40
    Last Post: 09-01-2006, 01:09 AM
  3. Replies: 0
    Last Post: 04-27-2003, 03:04 AM
  4. Replies: 3
    Last Post: 01-14-2003, 10:34 PM

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