Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- #include <time.h>
- #include <stdlib.h>
- using namespace std;
- void colore(unsigned short color)
- {
- HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(hcon,color);
- }
- void gotoxy( int column, int line )
- {
- COORD coord;
- coord.X = column;
- coord.Y = line;
- SetConsoleCursorPosition(GetStdHandle( STD_OUTPUT_HANDLE ),coord);
- }
- int main()
- {
- srand((unsigned)time(NULL)); // inizializza il seme
- int s = rand() %10 +1; //asseg
- int a=0;
- int tent_max=5;
- int tent=0;
- while(tent <= tent_max)
- {
- colore(12);
- cout << "HAI " << tent_max-tent <<" TENTATIVI" <<endl;
- colore(14);
- cout << "INDOVINA IL NUMERO: ";
- cin >> a;
- if(a < s)
- {
- colore(12);
- cout << "Inserisci un numero piu' grande!!! RITENTA" <<endl;
- tent++;
- }
- else if(a > s)
- {
- colore(12);
- cout << "Inserisci un numero piu' piccolo!!! RITENTA" <<endl;
- tent++;
- }
- else
- {
- colore(10);
- cout << "HAI INDOVINATO IL NUMERO" <<endl;
- return 0;
- }
- }
- colore(10);
- cout << "HAI PERSO... IL NUMERO ERA " << s;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement