1
0
This commit is contained in:
Captain ALM 2022-10-07 12:35:44 +01:00
parent a7efeab624
commit 18c5f972c2
Signed by: alfred
GPG Key ID: 4E4ADD02609997B1

View File

@ -1,14 +1,30 @@
#include <iostream>
#include <cstdlib>
#include <ctime>
using string = std::string;
int main() {
std::cout << "Enter your name:\n";
string name;
std::cin >> name;
std::cout << "Hello, " << name << "!\n";
for (int i {0}; i < static_cast<int>(name.size()) + 8; i++) {
std::cout << "=";
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 ; ";
}
std::cout << "\n";
gcount++;
cout << "Guess again: ";
cin >> guess;
}
cout << "Correct!\n";
cout << "Took " << gcount << " tries.\n";
return 0;
}