Please help worth C++ program Change Machi 1. Create a Roulette Game Create a Th
ID: 3729408 • Letter: P
Question
Please help worth C++ program
Change Machi 1. Create a Roulette Game Create a The game will display the possible bet types. There will be 6 types of roulette table. a. bets on this Even (payout: 1-1) 1* 12 (payout: 2-1) 3rd 12 (payout: 2-1) Odd (payout: 1-1) 2nd 12 (payout: 2-1) Specific number 1-36 (payout: 35-1) b. The c. The game will allow the player to enter the bet amount. d. If the player is playin g on a specific number, the game will need to allow the player to e. f. enter the number they are placing their chip on The game should then randomly choose a roulette number to land on (1-36 The game should then determine if the player one and display output. the appropriate e player did not win, indicate so, and what their number and the roulette umber were (if they chose a number, else state their bet range: Even, Odd, 1" 12, 2nd 12, 3d 12) a. If th b. If the player did win, indicate so and what their winnings are Here are a few sample runs of the program 2 - Odd (payout: 1-1) 4 2nd 12 (payout: 2-1) 6 Specific number 1-36 (payout: 35-1) 1 - Even (payout: 1-1) 3 - 1st 12 (payout: 2-1) 5- 3rd 12 (payout: 2-1) How would you like to bet?1 How much money would you like to bet? $10 Press the Enter key to spin the roulette whee Roulette wheel spinning... Roulette wheel spinning You bet on even and the roll was 2. You win $ 10.0 1 - Even (payout: 1-1) 3- 1st 12 (payout: 2-1) 5- 3rd 12 (payout: 2-1) 2 Odd (payout: 1-1) 4-2nd 12 (payout: 2-1) 6- Specific number 1-36 (payout: 35-1) How would you like to bet?6 How much money would you like to bet? $10 What number do you want to place your chip on? 14 Press the Enter key to spin the roulette wheel Roulette wheel spinning... Roulette wheel spinning You bet on the number 14 and the winning number was 12. Sorry, you loseExplanation / Answer
Solution:
code:
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
using namespace std;
struct node {
int data;
char ch;
struct node *prev, *next;
};
struct node *head = NULL, *tail = NULL;
struct node *createNode(int);
void insertNode(int);
void deleteNode(int);
void display();
struct node* createNode(int data,char ch) {
struct node *ptr = (struct node *)malloc(sizeof (struct node));
ptr->data = data;
ptr->ch=ch;
ptr->prev = NULL;
ptr->next = NULL;
return (ptr);
}
/* insertion in circular linked list */
void insertNode(int data,char ch) {
struct node *temp, *ptr = createNode(data,ch);
/* list is empty */
if (!head) {
head = ptr;
head->next = head;
head->prev = head;
tail = head;
return;
} else {
/* only one node present in list */
if (head->next == head && head->prev == head) {
temp = head;
ptr->next = temp;
ptr->prev = temp->prev;
temp->prev = ptr;
temp->next = ptr;
tail = ptr;
} else {
/* do insertion next to head */
temp = head->next;
ptr->next = temp;
ptr->prev = temp->prev;
temp->prev->next = ptr;
temp->prev = ptr;
}
}
}
/* traversing the list */
void displayforward(int r) {
struct node *ptr = head;
int i = 0;
while (r--) {
cout<<ptr->ch<<ptr->data<<" ";
ptr = ptr->next;
i++;
}
cout<<"you landed on "<<(ptr->prev)->ch<<(ptr->prev)->data<<" ";
}
void displaybackward(int r) {
struct node *ptr = head;
int i = 0;
while (r--) {
cout<<ptr->ch<<ptr->data<<" ";
ptr = ptr->prev;
i++;
}
cout<<"you landed on "<<ptr->next->ch<<ptr->next->data<<" ";
}
int main() {
int i,data,r;
char ch;
// roulette wheel layout taken from wikipedia
int val[]={0,32,15,19,4,21,2,25,17,34,6,27,13,36,11,30,8,23,10,5,24,16,33,1,20,14,31,9,22,18,29,7,28,12,35,3,26};
for(i=0;i<37;i++)
{
if((val[i]>=1 && val[i]<=10) || (val[i]>=19 && val[i]<=28))
{
if(val[i]%2==0)
ch='b';
else ch='r';
}
else if((val[i]>=11 && val[i]<=18) || (val[i]>=29 && val[i]<=36))
{
if(val[i]%2!=0)
ch='b';
else ch='r';
}
else if(val[i]==0) ch='g';
insertNode(val[i],ch);
}
srand(time(NULL));
r=rand()%400+100;
cout<<"Forward random number "<<r<<endl;
displayforward(r);
r=rand()%400+100;
cout<<"Backward random number "<<r<<endl;
displaybackward(r);
return 0;
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)