Advertisement
fabioceep

ParOuImpar

Apr 2nd, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4. //#include <conio.h>
  5.  
  6. using namespace std;
  7.  
  8. int main ()
  9. {
  10.     int pcNumero, seuNumero, ParImpar;
  11.     char resposta;
  12.  
  13.     //Gera um numero aleatorio
  14.     srand( (unsigned)time( NULL ) );
  15.     pcNumero = rand() % 100;
  16.  
  17.     cout << "Par ou Impar (P/I)? " << endl;
  18.  
  19.     //Leia o caracter e salve na variavel resposta
  20.     //resposta = toupper(getche());
  21.     cin >> resposta;
  22.     resposta = toupper(resposta);
  23.     cout << endl; //Pular linha
  24.  
  25.     cout << "Digite um numero " << endl;
  26.     //Leia o numero e salve na variavel seuNumero
  27.     cin >> seuNumero;
  28.  
  29.     ParImpar = (seuNumero + pcNumero) % 2;
  30.     cout << "O PC escolheu " << pcNumero << endl;
  31.  
  32.     if(!ParImpar){
  33.         cout << "Resultado: Par" << endl;
  34.     }
  35.     else
  36.     {
  37.         cout << "Resultado: Impar" << endl;
  38.     }
  39.  
  40.     if(resposta=='P'){
  41.         cout << "Voce escolheu Par" << endl;
  42.     }
  43.     else
  44.     {
  45.         cout << "Voce escolheu Impar" << endl;
  46.     }
  47.  
  48.     if ((!ParImpar) && (resposta=='P'))
  49.     {
  50.         cout << "Voce ganhou!!!" << endl;
  51.     }
  52.     else
  53.     {
  54.         cout << "Voce perdeu!!!" << endl;
  55.     }
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement