Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <time.h>
- #include <cmath>
- #include <windows.h>
- using namespace std;// |
- int main(void)
- {
- HANDLE h= GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(h,FOREGROUND_RED |FOREGROUND_INTENSITY);
- SetConsoleTextAttribute(h,BACKGROUND_BLUE);
- system ("CLS");
- bool gameFinished=false;
- cout<<"compuerul isi va imagina un nr de 1 la un nr scris de tine ,scrie numarul : ";
- int input_nr,nr,numrand,trynr=0;
- cin>>nr;
- long double chance=100/(float)nr;
- cout<<"deci computerul isi va imagina un nr de la 1 la "<<nr<<" incearca sa il ghicesti (daca vrei sa renunti scrie 0) :"<<endl;
- cout<<"sansele tale sunt "<<chance<<"%"<<endl;
- while (!gameFinished) {
- cout<<"nr e: ";
- srand(time(NULL));
- numrand=rand()%nr+1;
- cin>>input_nr;
- trynr++;
- if (numrand==input_nr) {
- cout<<"ai castigat"<<endl;
- cout<<"incercari: "<<trynr;
- gameFinished=true;
- }
- else if (input_nr==0)
- {
- cout<<"ai renuntat dupa "<<trynr-1<<" incercari ";
- gameFinished=true;
- }
- else
- {
- cout<<"ai pierdut"<<endl<<" numaru era "<<numrand<<endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement