-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdado_monetina.cpp
More file actions
35 lines (33 loc) · 944 Bytes
/
dado_monetina.cpp
File metadata and controls
35 lines (33 loc) · 944 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
srand(time(NULL));
int numero_previsto;
int numero_uscito;
int tentativi=0;
while (tentativi<2) {
cout<<"hai ancora "<<tentativi<<" tentativi"<<endl;
cout<<"prova ad indovinare (0 per testa, 1 per croce): ";
cin>>numero_previsto;
numero_uscito = rand()%2;
if (numero_uscito==0) {
cout<<"e' uscito testa"<<endl;
}else {
cout<<"e' uscito croce"<<endl;
}
if (numero_previsto == numero_uscito) {
cout<<"Complimenti hai indovinato!!!"<<endl;
return 0;
}
tentativi=tentativi + 1;
if (tentativi<2){
cout<<"Ritenta NON hai indovinato!!!"<<endl;
}
else {
cout<<"hai esaurito il numero di tentativi"<<endl;
}
}
return 0;
}