1
0
LearningCPP/main.cpp
2022-10-14 12:08:17 +01:00

34 lines
699 B
C++

#include <iostream>
#include <cstdlib>
#include <ctime>
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;
}
cout << "Correct!\n";
cout << "Took " << gcount << " tries.\n";
return 0;
}