Advertisement
STANAANDREY

game

Nov 9th, 2018
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <time.h>
  4. #include <cmath>
  5. #include <windows.h>
  6. using namespace std;//   |
  7. int main(void)
  8. {
  9.     HANDLE h= GetStdHandle(STD_OUTPUT_HANDLE);
  10.    SetConsoleTextAttribute(h,FOREGROUND_RED |FOREGROUND_INTENSITY);
  11.    SetConsoleTextAttribute(h,BACKGROUND_BLUE);
  12. system ("CLS");
  13.  
  14. bool gameFinished=false;
  15. cout<<"compuerul isi va imagina un nr de 1 la un nr scris de tine ,scrie numarul : ";
  16. int input_nr,nr,numrand,trynr=0;
  17. cin>>nr;
  18.    long double chance=100/(float)nr;
  19. cout<<"deci computerul isi va imagina un nr de la 1 la "<<nr<<" incearca sa il ghicesti (daca vrei sa renunti scrie 0) :"<<endl;
  20. cout<<"sansele tale sunt "<<chance<<"%"<<endl;
  21. while (!gameFinished) {
  22.         cout<<"nr e: ";
  23. srand(time(NULL));
  24. numrand=rand()%nr+1;
  25.  
  26. cin>>input_nr;
  27. trynr++;
  28.    if (numrand==input_nr) {
  29.     cout<<"ai castigat"<<endl;
  30.     cout<<"incercari: "<<trynr;
  31.    gameFinished=true;
  32. }
  33.    else if (input_nr==0)
  34.    {
  35.        cout<<"ai renuntat dupa "<<trynr-1<<" incercari ";
  36.        gameFinished=true;
  37.    }
  38.     else
  39.     {
  40.         cout<<"ai pierdut"<<endl<<" numaru era "<<numrand<<endl;
  41.  
  42.     }
  43. }
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement