Guess Number with artificial intelligence (Version 1.1.5)





Source codes:

// Guess my number game
// The game is written by "Syed Ali Haider"
// Student of Havjery University
// Don't remove these line for legal use
// Upload on Let's programming by (CEO)
// For more games contact
// key_to_programming@yahoo.com
#include <iostream>
#include <time.h> // header file for time
#include <conio.h> // for using getch funciton

using namespace std;
int random_number() //function for random number
{
      
       srand(time(NULL)); // for random number

       int r_number=rand()%10; // % 10 indicate that the number is from 0 to 9
      
       return r_number;
      
}


void main ()
{
       cout<<"\t\t|..Welcome to Guess my number Game..|\n\t\t\tAre you genius..??\n\t\t\t Let's prove....!"<<endl<<endl;
       cout<<"-------------------------------------------------------------------------"<<endl<<endl;
       char op; // for again play option
       do

       {

       int turn=0; // for count the turn which is played by user
       int ans; // any value for secure form error
       int  r_n =random_number(); // random number

       cout<<"\t\t:Your hints:"<<endl;
       cout<<"\t\t----------"<<endl<<endl;
       cout<<"\tThe number will be from \"0 to 9\""<<endl;
       //cout<<"\tThe random number is: "<<r_n<<endl;

      
      
       if (r_n%2==0) //for check whether the number is even or ood
             cout<<"\tThe hidden number is even.\n";
       else
             cout<<"\tThe hidden number is odd.\n";


             int counter=0; // for for loop
      
             for (int pm=1; pm<=r_n; pm++) // for check that whether the number is prime or not
                    {
                                 if (r_n % pm ==0)
                                 counter=counter+1;
                    }

             if (counter==2)
                    cout<<"\tThe hidden number is prime number.\n";
             else
                    cout<<"\tThe hidden number is not prime number."<<endl;


             if (r_n==0) // if the number is 0 then it alert the use that it might bt zero

                    cout<<"\tMay be the number is zero."<<endl;
             else
                    cout<<"\tThe hidden number is not zero."<<endl;


       for (int j=1; j<=2;) // an infinite loop

       { //for loop starts here
             cout<<"\n\n\nWhats the number be....?"<<endl;
             cout<<"For help enter \"111\" ...!"<<endl;
             cout<<"\nPlease enter your guess here: ";
             cin>>ans;

             turn++; // for count how many turns are played

             if (ans==111)
             {
             cout<<"The hidden number is: "<<r_n<<endl;
             break;
             }
             else

             if (ans==r_n)
             {
                    cout<<"Wow.....After ("<<turn<<") attempt(s) You guess the hidden number"<<endl;
                    break;
             }
             else
                    cout<<"\nTry again.."<<endl;

      
             cout<<"Its your "<<turn<<" turn..!"<<endl;
       }// for loop ends here

       cout<<"\nDo you play again (Y/N): ";
        cin>>op;
        cout<<endl<<"!---------------------------------------------------!"<<endl;
       }

       while (op=='y' || op=='Y');

       cout<<endl<<endl;
       cout<<"Thanks for play the game......!";

getche(); // for not automatic end
cout<<endl<<endl; // for space only
}
 // Guess my number game
// The game is written by "Syed Ali Haider"
// Student of Havjery University
// Don't remove these line for legal use
// Upload on Let's programming by (CEO)
// For more games contact
// key_to_programming@yahoo.com

Comments

Popular posts from this blog

Umbrella activities in Software Engineering

Operating System | Best Definition of Opetating System