Ejemplo: c ++ adivina mi número
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int num, guess, tries = 0;
srand(time(0)); //seed random number generator
num = rand() % 100 + 1; // random number between 1 and 100
cout << "Guess My Number Gamenn";
do
{
cout << "Enter a guess between 1 and 100 : ";
cin >> guess;
tries++;
if (guess > num)
cout << "Too high!nn";
else if (guess < num)
cout << "Too low!nn";
else
cout << "nCorrect! You got it in " << tries << " guesses!n";
} while (guess != num);
return 0;
}
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)