#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    13
    Rep Power
    0

    Question repeating a program


    I was just wondering if there was a simple way of repeating my program... heres and exapmle...
    #include <iostream.h>
    #include <stdlib.h>
    main()
    {

    int number = 5;
    int guess;

    cout <<"choose a number between 1 and 50000"<<endl;
    cout <<"inter your guess"<<endl;
    cin>>guess;
    if (guess == number)
    {
    cout << "WOW YOUR RIGHT!!!"<< endl;

    }
    else if (guess < number)
    {
    cout <<"guess higher!"<<endl;
    }
    else
    {
    cout <<"guess lower!"<<endl;
    }
    system("PAUSE");
    return 0;
    }

    it just asks you to guess a number and if you guess it wrong the tells you what you need to do (higher or lower). How do i make it to were it tells you higher or lower, and then let you do it again without closeing?
  2. #2
  3. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,117
    Rep Power
    1803
    A while loop. (or a do-while).

    E.g.
    Code:
    do
    {
       // your existing code body here
    
    } while( guess == number ) ;

    Clifford
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    13
    Rep Power
    0
    were exactly do i put it... before in the code
    and were do i end it...
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    13
    Rep Power
    0
    never mind i found it

IMN logo majestic logo threadwatch logo seochat tools logo