Le ho provate tutte, dato che sono agli inizi, volevo cimentarmi un un programma(gioco)
Ma non riesco a generare 2 numeri casuali, me ne genera solo 1
source:
codice:
#include <cstdlib>
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
using namespace std;
int main(int argc, char *argv[])
{
char player1[20], player2[20];
int scelta;
srand((unsigned)time(NULL));
int d1 = rand()%7;
srand((unsigned)time(NULL));
int d2 = rand()%7;
cout << "Questo programma simula una partita a dadi tra 2 persone" << endl;
cout << "Scegli un opzione" << endl;
cout << "1 \t GIOCA!" << endl;
cout << "0 \t ESCI" << endl;
cin >> scelta;
switch(scelta)
{
case 1:{
cout << "Inserisci nome player 1: \t";
cin >> player1;
cout << "Inserisci nome player 2: \t";
cin >> player2;
Sleep(1000);
cout << player1 << " Hai fatto \t" << d1 << endl;
Sleep(1000);
cout << player2 << " Hai fatto \t" << d2 << endl;
if(d1 > d2) cout << "Ha vinto \t" << player1 << endl;
else cout << "Ha vinto \t" << player2 << endl;
system("PAUSE");
}
case 0: return EXIT_SUCCESS;
}
return EXIT_SUCCESS;
system("PAUSE");
}
Dov'è che sbaglio?