Skip to content
Snippets Groups Projects
Commit 23119022 authored by Rudi Buss's avatar Rudi Buss
Browse files

Update Solution Exercise 3 - Guessing numbers.cpp

parent 8f68e61a
No related branches found
No related tags found
Loading
#include <iostream>
#include <ctime>
#include <iostream>
using namespace std;
int main() {
int number, input, tries = 0;
srand(time(NULL));
number = rand() % 100 + 1; // Random number between 0 and 99 is generated, therefore +1, so that the number is between 1 and 100
do {
cout << "Input a number: ";
cin >> input;
if (input > number) cout << "Too large!" << endl;
if (input < number) cout << "Too small!" << endl;
tries++;
} while (input != number && tries < 6);
int main ()
{
int number, input, tries=0;
srand (time(NULL));
number = rand()%100 + 1; //Random number between 0 and 99 is generated, therefore +1, so that the number is between 1 and 100
if (input == number)
cout << "You guessed the right number!" << endl;
else
cout << "You lost! The number was " << number << endl;
do
{
cout << "Input a number: ";
cin >> input;
if(input > number)
cout << "Too large!" << endl;
if(input < number)
cout << "Too small!" << endl;
tries++;
}
while(input != number && tries < 6);
if (input == number)
cout << "You guessed the right number!" << endl;
else
cout << "You lost! The number was " << number << endl;
return 0;
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment