I am developing a game where the user plays a slot machine. The slot machine needs to randomise the 3 different symbols in nine pieces fields, for example the symbols:
A A A O A O X X X
I am using a two-dimensional array but I don't know how to randomise the array? The second problem. I don't know how to compare the symbols in the array? The goal of the game is to obtain as many rows, columns, and diagonals as possible of the same symbol. In the above example, obtained a profit when the upper and lower line have equal symbols, partly 2x lines. Depending on the number of rows with the same symbol the user gets paid as the profit system follows:
•A series provides 2 * bet •Two lines giving 3 * bet •Three rows giving 4 * bet •Four rows gives 5 * bet •Five lines gives 7 * bet •Fully playing field gives 10 * bet
I don't know how to fix this problem with the rows and money? Can someone help me with the code?
This is my code for the two-dimensional array: I don't know if Im doin the right thing so can someone please help me. I just started learning c++. I wan to randomise the symbols and compare them.
char game[3][3] = {{'X','X','X'}, {'A','A','A'}, {'O','O','O'}};
cout << game[0][0] << game[0][1] << game[0][2] << "\n";
cout << game[1][0] << game[1][1] << game[1][2] << "\n";
cout << game[2][0] << game[2][1] << game[2][2] << "\n";
#include <iostream>
include
include
include
using namespace std;
void insertmoney();
void newgame();
void slot();
int money, moneyleft = 0;
int bet;
int main()
{
int mainmenu = 1;
system("CLS");
cout << endl;
cout << "Options:\n" << endl;
cout << " [1] Start New Game\n\n\n"
<< " [2] Quit\n\n";
cin >> mainmenu;
if (mainmenu < 1 || mainmenu > 2)
{
system("CLS");
main();
}
if(mainmenu == 1)
{
insertmoney();
}
if(mainmenu == 2)
{
return 0;
}
newgame();
slot();
system("pause");
return 0;
}
void insertmoney()
{
system("CLS");
do
{
cout << "Please insert money: 100 SEK, 300 SEK or 500 SEK\n";
cin >> money;
}while(money != 100 && money != 300 && money != 500);
cout << "Insert is accepted!" << endl;
cout << "Current insert is: " << money << endl;
moneyleft += money;
system("pause"); }
void newgame()
{
system("CLS");
do
{
cout << "Please place your bet: " << endl;
cout << "OBS: You are not allowed to exceed the amount of insert money!" << endl;
cin >> bet;
}while(bet > money);
cout << "Bet is accepted!" << endl;
cout << "Current bet is: " << bet << endl;
moneyleft -=bet;
system("pause"); }
void slot() { system("CLS"); int slotmenu; cout << endl; cout << "[1] Play\n" << "[2] Main Menu\n\n"; cin >> slotmenu; if (slotmenu == 1) { system("CLS"); cout << "Your bet is: " << bet << endl; cout << "The game is on!!!" << endl; cout << endl; bet--;
char symbs[] = {'O','X','A'};
char game[3][3];
for (int i = 0; i != 3 ; i++)
{
for (int j = 0; j != 3 ; j++)
{
int rndnum = round((double)rand() / (double) RAND_MAX * 3);
game[i][j] = symbs[rndnum];
}
}
}
}