1
0
LearningCPP/main.cpp

34 lines
699 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)
{
2022-10-14 12:08:17 +01:00
if (guess > secret)
{
2022-10-07 12:35:44 +01:00
cout << "Number too big ; ";
2022-10-14 12:08:17 +01:00
}
else
{
2022-10-07 12:35:44 +01:00
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;
}