WSQ06 – Pick a Number

código:

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <conio.h>
using namespace std;
int main()
{
int num1,num2,i=1;
char des;
cout <<“nI have a number chosen between 1 and 100.”<<endl;
num1=rand()%100 + 1;
//cout<<“n”<<num1;
cout <<“nPlease guess a number between 1 and 100:”;
cin>>num2;
while (num1!=num2)
{
if (num1 < num2)
{
cout <<“nI am sorry but “<< num2 << ” is too high, try again:”;
cin>>num2;
}
else
{
cout <<“nI am sorry but “<< num2 << ” is too low, try again:”;
cin>>num2;
}
i++;
}
cout <<“nYou got it! The right answer is indeed”<<num1;
cout <<“nYou made “<< i << ” guesses to get the right number.”<<endl;
getch();
return 0;
}

CC BY-SA 4.0 WSQ06 – Pick a Number by perape is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.