consider this prgram, this is game called 'beat that'.in this game,a player will roll four dice.the program must generate a random number between 1and6 for different dice:
#include <cstdlib>
#include <iostream>
#include <ctime>
#include <string>
using namespace std;
void print(int dice);
//this is the seed function
void rand_seed(){
int seed = (int)(time(0));
srand(seed);
}
//this function generates a random number between 0 - 6 (1,2,3,4,5)
int dice_roll(){
return 1 + rand() % (6 - 1 + 1);
}
void swap(int &x, int &y) {
int temp;
if(x < y){
temp = x;
x = y;
y = temp;
}
}
int d1 = dice_roll();
int d2 = dice_roll();
int d3 = dice_roll();
int d4 = dice_roll();
//output
cout << "4 dices are trown....." << endl;
print(d1),print(d2),print(d3),print(d4);
int largest = arrange(d1,d2,d3,d4);
cout<<"to play again press: 'p'& F9"<<endl;
cout<<endl<<endl;
cout<<"to stop, just press: 's'"<<endl;
return 0;
}
The problem is that i need to ask a user if he/she wishes to continue with playing this game or to stop ,so I dont know how to do so. can anyone please do it for me.
//this function generates a random number between 0 - 6 (1,2,3,4,5)
int dice_roll(){
return 1 + rand() % (6 - 1 + 1);//<< This will give (1,2,3,4,5,6) not (1,2,3,4,5)
}