954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Program help

Hello, i have a couple questions. im making a simple program were the user has to guess a number. One of my problems is that ounce they enter a number, they have to restart the program to guess again because it will quit if they guess it after the first time. What would i use to make it so after they guess one time it restarts itself at a certain point. heres my code. Also what does BOOL mean? Thx


#include
#include
#include

using namespace std;

int main(int argc, char *argv[])
{
int number;
cout<<"Find the lucky number, made by d3|dr!cK, pick a number 1-3"<>number;
cin.ignore();


if ( number == 1)
{
cout<<"#1, good choice but,not a cool number, pic another number...";

}


if ( number == 3)
{
cout<<"#3, pic another number...";

}


if ( number == 2)
{
cout<<"#2, Good job";


}


if (number > 3)
{
cout<< " Enter a number beetween one and five";
}

cin.get();
}

fitfool
Newbie Poster
7 posts since Mar 2006
Reputation Points: 10
Solved Threads: 0
 
#include<iostream>
#include<ctime>
using namespace std;

int main()
{
    int number = 0,
        guess  = 0;        
    bool again = true;    
    char answer;
    
    srand(time(NULL));
    
    do{
                  
         number = rand()%3 + 1;
        
         cout << "\n\tGuess a number from 1 to 3: ";
         cin >> guess;
         
         while(again)
         {
            if(number == guess)
            {
               cout << "\n\tGood guess!  The correct number was " << number;
               again = false;
            }
            
            else
            {
                cout << "\n\tIncorrect!  "<< guess << " is not the right answer.";
                cout << "\n\tTry again.";
                cout << "\n\n\tGuess a number from 1 to 3: ";
                cin >> guess;           
            }
         }
           
         cout << "\n\n\tWould ye' like to try again? (Y/N) ";
         cin >> answer;
         
         again = true;
         
         }while(answer == 'Y' || answer == 'y');
         
   return 0;
}
Clinton Portis
Practically a Posting Shark
833 posts since Oct 2005
Reputation Points: 237
Solved Threads: 118
 

"bool" is short for "boolean" - look it up in any dictionary or computer science website. in C++, bool is a data type for an object which accepts only true and false (or, alternatively, zero for false, and non-zero for true)

Bench
Posting Pro
577 posts since Feb 2006
Reputation Points: 307
Solved Threads: 63
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You