I am trying to create a nim game, and I am trying to generate random numbers which is used in the game, but it does not work. Here is my code:
#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;
string player1name,player2name,player1status,player2status,pile1,pile2,pile3;
int main(){
cout<<"What is player 1's name?"<<endl;
getline(cin, player1name);
cout<<"What is player 2's name?"<<endl;
getline(cin, player2name);
pile1 = rand() % 40 + 1;
cout<<pile1;
return 0;
}
It compiles successfully, but its output is like this:
What is player 1's name?
Ttyeuo yuwew
What is player 2's name?
Yiefwh HYoaw
?
--------------------------------
Process exited after 15.84 seconds with return value 0
Press any key to continue . . .
So the random number generator does not function properly, but I cannot figure out why it happens. Can somebody help me solve this question or suggest a better way to generate random numbers?
Aucun commentaire:
Enregistrer un commentaire