Advertisement
costa99

INDOVINA IL NUMERO

May 26th, 2015
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.30 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <time.h>
  4. #include <stdlib.h>
  5.  
  6. using namespace std;
  7.  
  8. void colore(unsigned short color)
  9. {
  10.  HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
  11.  SetConsoleTextAttribute(hcon,color);
  12. }
  13.  
  14. void gotoxy( int column, int line )
  15. {
  16.  COORD coord;
  17.  coord.X = column;
  18.  coord.Y = line;
  19.  SetConsoleCursorPosition(GetStdHandle( STD_OUTPUT_HANDLE ),coord);
  20. }
  21.  
  22.  
  23. int main()
  24. {
  25.     srand((unsigned)time(NULL)); // inizializza il seme
  26.     int s = rand() %10 +1; //asseg
  27.     int a=0;
  28.     int tent_max=5;
  29.     int tent=0;
  30.     while(tent <= tent_max)
  31.     {
  32.         colore(12);
  33.         cout << "HAI " << tent_max-tent <<" TENTATIVI" <<endl;
  34.         colore(14);
  35.         cout << "INDOVINA IL NUMERO: ";
  36.         cin >> a;
  37.         if(a < s)
  38.         {
  39.             colore(12);
  40.             cout << "Inserisci un numero piu' grande!!! RITENTA" <<endl;
  41.             tent++;
  42.         }
  43.         else if(a > s)
  44.         {
  45.             colore(12);
  46.             cout << "Inserisci un numero piu' piccolo!!! RITENTA" <<endl;
  47.             tent++;
  48.         }
  49.         else
  50.         {
  51.             colore(10);
  52.             cout << "HAI INDOVINATO IL NUMERO" <<endl;
  53.             return 0;
  54.         }
  55.     }
  56.     colore(10);
  57.     cout << "HAI PERSO... IL NUMERO ERA " << s;
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement