Created
March 25, 2022 17:32
-
-
Save divanibarbosa/9de41262cf8e717e2c0e5f29b3d55c3d to your computer and use it in GitHub Desktop.
Jogo adivinha número em linguagem C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Criado por: profa. Divani Barbosa Gavinier | |
// Currículo Lattes: http://lattes.cnpq.br/8503400830635447 | |
// [email protected] | |
#include <iostream> | |
#include <stdlib.h> | |
#include <time.h> | |
using namespace std; | |
int GeraNum(int); | |
int AdivinhaNum(); | |
main() { | |
cout << "Jogo do Adivinha\n"; | |
cout << "Quantidade de chutes foi: "<< AdivinhaNum() << endl; | |
} | |
int GeraNum(int x) { | |
srand(time(NULL)); | |
return rand()%(x+1); | |
} | |
int AdivinhaNum() { | |
int x, valor, chute, i=0; | |
cout << "Informe um valor para o intervalo [0,x] para que eu gere um valor aleatorio:\n"; | |
cout << "Valor de x: "; | |
cin >> x; | |
valor = GeraNum(x); | |
cout << "Descubra o valor aleatorio gerado.\n"; | |
do { | |
cout << "Responda qual eh o valor? "; | |
cin >> chute; | |
i++; | |
if(chute > valor) cout << "Muito alto. Tente novamente...\n"; | |
else if(chute < valor) cout << "Muito baixo. Tente novamente...\n"; | |
else { | |
cout << "ACERTOU!!\n"; | |
break; | |
} | |
} while(1); | |
return i; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment