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 <stdlib.h>
#include <stdio.h>
#include <iostream>

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"<<endl;
cin>>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();
}

#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;
}

"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)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.