1
0
LearningCPP/main.cpp

31 lines
672 B
C++
Raw Normal View History

2022-08-12 14:59:08 +01:00
#include <iostream>
2022-10-07 12:35:44 +01:00
#include <cstdlib>
#include <ctime>
2022-08-13 00:34:25 +01:00
2022-10-07 12:35:44 +01:00
int main()
{
using std::cout;
using std::cin;
srand(time(nullptr));
int gcount{ 1 };
int n { 20 };
int secret { rand()%n + 1 };
cout << "Guess a number between 1 and " << n << ": ";
int guess;
cin >> guess;
while (guess != secret)
{
if (guess > secret) {
cout << "Number too big ; ";
} else {
cout << "Number too small ; ";
}
gcount++;
cout << "Guess again: ";
cin >> guess;
2022-10-07 12:18:23 +01:00
}
2022-10-07 12:35:44 +01:00
cout << "Correct!\n";
cout << "Took " << gcount << " tries.\n";
return 0;
}