-
Notifications
You must be signed in to change notification settings - Fork 0
/
wsq06.cpp
31 lines (28 loc) · 787 Bytes
/
wsq06.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
#include <cstdlib>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main ()
{
srand (time(NULL));
int x = rand () % 100 + 1; //Random number generated by the program
int y; //User input number
int n = 0; //Counter
cout << "Please try to guess the number (between 0 and 100)." << endl;
do {
cin >> y;
if (y>x){
cout << "The number you entered is higher than the secret number... try again." << endl;
}
if (y<x){
cout << "The number you entered is lower than the secret number... try again." << endl;
}
if (y==x){
cout << "Congratulations! You guessed the number!" << endl;
}
n++;
}while (y!=x);
cout << "Number of tries: " << n << endl;
return 0;
}