Best writers. Best papers. Let professionals take care of your academic papers

Order a similar paper and get 15% discount on your first order with us
Use the following coupon "FIRST15"
ORDER NOW

I am working on this school assignment to setup a horse race

I am working on this school assignment to setup a horse race.  I attached the code I have so far but I have a bug

I cant figure out how to fix.  my horses[] ids 1-6 are not matching hnum the horse I bet on so I am always losing.  It does not win with any horse.  I know I am missing something that matches the horses[].id to hnum but I am having a hard time figuring it out.  Any help would be great.  Thank you ATTACHMENT PREVIEW Download attachment// Week 4 Assignment-3// Description: Horserace//———————————-//**begin #include fles************#include<iostream>// provides access to cin and cout#include<array>// provides access to std::array#include<time.h>// provides access to time()#include<string>// provides access to getline()#include<iomanip>//–end oF #include fles———–//———————————-usingnamespacestd;//———————————-//**begin global constants**********constinthorseCount = 6;constinttrackLength = 100;// struct For horsestructHorse{stringname;intdistance;inteventO±set;intID;};//–end oF global constants———//———————————-array<Horse, horseCount> horses;//**begin main program**************intmain(){//IDs oF the horseshorses[0].ID = 1;horses[1].ID = 2;horses[2].ID = 3;horses[3].ID = 4;horses[4].ID = 5;horses[5].ID = 6;//——————————————–// seed random number generatorsrand(time(NULL));// create and initialize variables// create horsesFor(Horse&h : horses)// have user name horses (range-based For loop){cout<<“What’s the name oF this horse? “;cin>>h.name;cout<<endl;}//——————————————-intbet;// betintcash = 100;// cash on hand//——————————————-

Background image of page 1

View the Answerboolracing =false;boolplaying =true;inthNum;// horse number bet on//——————————————-// start of game loopwhile(playing ==true){cout<<“You have $”<<cash<<” with you.”<<endl;cout<<“How much are you willing to bet? “;cin>>bet;// ask for bet amountif(bet <= 0)// if bet is less than or equal to $0– quit{playing =false;}else// else get the number of the horse being bet on{cout<<“Which horse number (from 1-6) do you want to bet on? “;cin>>hNum;cout<<endl;racing =true;cash = (cash – bet);cin.sync();}// start of race loopwhile(racing ==true){cout<<“We are ready to go!!!!”<<endl;// for each horse–use range-based fordo{for(Horse&h : horses){// two 1-6 dice —————————–intdie1 = rand() % 6 + 1;intdie2 = rand() % 6 + 1;intsum;// sum of dice roll//——————————————-sum = (die1 + die2);switch(sum)// use switch statement to handle event{case0:sum = (sum – ((rand() % 2) + 1));cout<<h.name<<” broke its stride!”<<endl;break;case1:sum = (sum – ((rand() % 2) + 1));cout<<h.name<<” broke its stride!”<<endl;break;case2:sum = (sum + ((rand() % 2) + 1));cout<<h.name<<” found its stride!”<<endl;break;case3:sum = (sum + ((rand() % 2) + 1));cout<<h.name<<” found its stride!”<<endl;break;case4:

Background image of page 2

Show

 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"