This is my “Pick a Number” program, in which the computer thinks in a number between one and a hundred. The user will try to guess the number. When the user finally get it, the computer will show the number of attemps.
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
int main()
{
int A, B, C =0;
srand (time(NULL));
B = 1 + rand ()%100;
while (A!=B)
{
C=C+1;
cout<<“Guess a number between 1 and 100.”<<endl;
cin >>A;
if(A<B)
{
cout<<“ÑO… Too low :´( “<<endl;
}
else if (A>B)
{
cout<<“ÑO… Too high :´(“<<endl;
}
}
cout<<“GOOD, GOOOOOOOOOOD”<<endl;
if (C>5)
{
cout<<“You suck, you take “<<C<<” attemps.”<<endl;
}
else
{
cout<<“Well done, you take “<<C<<” attemps.”<<endl;
}
return 0;
}
#WSQ06 Pick a Number by José Enríquez is licensed under a Creative Commons Attribution 4.0 International License.