This topic is a little bit hard because the line of random numbers! so I decided to use
srand(time(NULL);
then I choose the variable A so…
A= rand()%100+1;
this means that I choose the range of random numbers 1 to 100 .
ADVICE:It is better to write fewer lines of code to make it much more clear and simple , if you do a lot of lines , it is more difficult to understand and interpet. So just make it Simple 😀
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
int main (){
int A, B, C=1 ;
srand(time (NULL));
A = rand () % 100 + 1;
do{
cout << “Try a guess” << endl;
cin >> B;
C=C+1;
if (B < A){
cout << “Wrong!, it’s too low” << endl;
}
if (B>A) {
cout << “Wrong!, it’s too high” << endl;
}
} while ( B!=A);
cout << “You got it!! you guess the number.” << endl;
cout << “You try to gueess the number ” << C<< ” times” << endl;
cin >> C;
return 0;
}
#WSQ06 #TC1017
#WSQ06 #TC1017 by Alejandra Jacobo Gómez is licensed under a Creative Commons Attribution 4.0 International License.