I eventually want the output to count the number of win and loses for the amount of rolls it took
like 400 wins 500 loses with one roll
234 wins 434 loses with two rolls
...
I am wondering why my switch statement is not keeping count of gameWonOne, gameWonTwo, etc.
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
usingnamespace std;
//initalize the function
int diceToss();
int main()
{
int numberOfRolls = 0;
int totalNumberOfRolls =0;
int gameNumber = 0;
int rolledNumber = 0;
int pointNumber = 0;
int possibleRollsLeft =0;
int SIZE = 0;
int ROLLS =0;
double chanceOfWinning = 0;
int numberGamesWon = 0;
int numberGameslose = 0;
enum statusOfGame {WIN , LOSE, CONTINUE};
int gameHasBeenWon = 0;
int gameHasBeenLost = 0;
enum statusOfGame status;
srand(time(0));
//listing to store output in number games won in x rolls
int gameWonOne =0;
int gameWonTwo =0;
int gameWonThree=0;
int gameWonFour=0;
int gameWonFive=0;
int gameWonSix=0;
int gameWonSeven=0;
int gameWonEight=0;
int gameWonNine =0;
int gameWonTen =0;
int gameWonEleven=0;
int gameWonTwelve=0;
int gameWonThirteen=0;
int gameWonFourteen=0;
int gameWonFifteen=0;
int gameWonSixteen=0;
int gameWonSevenTeen=0;
int gameWonEighteen=0;
int gameWonNinteen=0;
int gameWonTwenty=0;
int gameWonTwentyOne=0;
int gameWontTwentyTwo=0;
int gameWonTwentyThree=0;
int gameWontTwentyFour=0;
int gameWontTwentyFive=0;
int gameWonTwentySix=0;
int gameWonTwentySeven=0;
int gameWonTwentyEight =0;
int gameWontTwentyNine=0;
int gameWonThirty=0;
//listing to store output in number games lost in x rolls
int gameLoseOne =0;
int gameLoseTwo =0;
int gameLoseThree=0;
int gameLoseFour=0;
int gameLoseFive=0;
int gameLoseSix=0;
int gameLoseSeven=0;
int gameLoseEight=0;
int gameLoseNine =0;
int gameLoseTen =0;
int gameLoseEleven=0;
int gameLoseTwelve=0;
int gameLoseThirteen=0;
int gameLoseFourteen=0;
int gameLoseFifteen=0;
int gameLoseSixteen=0;
int gameLoseSevenTeen=0;
int gameLoseEighteen=0;
int gameLoseNinteen=0;
int gameLoseTwenty=0;
int gameLoseTwentyOne=0;
int gameLosetTwentyTwo=0;
int gameLoseTwentyThree=0;
int gameLosetTwentyFour=0;
int gameLosetTwentyFive=0;
int gameLoseTwentySix=0;
int gameLoseTwentySeven=0;
int gameLoseTwentyEight =0;
int gameLosetTwentyNine=0;
int gameLoseThirty=0;
//setting precision for output to 2 decimal places
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
for( totalNumberOfRolls=1; totalNumberOfRolls < 5501; totalNumberOfRolls++)
{
rolledNumber = diceToss();
// win by rolling a 7 or 11 on first roll
if (rolledNumber == 7 || rolledNumber == 11)
{
status = WIN;
gameHasBeenLost++;
numberOfRolls = 1;
}
// lose by rolling a 2, 3, or 12
elseif (rolledNumber == 2 || rolledNumber == 3 | rolledNumber == 12)
{
status = LOSE;
gameHasBeenLost++;
numberOfRolls = 1;
}
// else need to roll the point before rolling a 7
else
numberOfRolls = 1;
{
pointNumber = rolledNumber;
do
{
//roll new number to compare to point
rolledNumber = diceToss();
if(rolledNumber == pointNumber)
{
status = WIN;
gameHasBeenWon++;
numberOfRolls++;
}
elseif (rolledNumber == 7)
{
status = LOSE;
gameHasBeenLost++;
numberOfRolls++;
}
else
status = CONTINUE;
numberOfRolls++;
//redo process
}
//keep user in loop until either wins or loses
while (rolledNumber != pointNumber && rolledNumber != 7);
}
switch (numberOfRolls)
{
case'1':
if (rolledNumber == pointNumber)
{
gameWonOne++;
}
else
{
gameLoseOne++;
}
break;
case'2':
if (rolledNumber == pointNumber)
{
gameWonTwo++;
}
else
{
gameLoseTwo++;
}
break;
case'3':
if (rolledNumber == pointNumber)
{
gameWonThree++;
}
else
{
gameLoseThree++;
}
break;
case'4':
if (rolledNumber == pointNumber)
{
gameWonFour++;
}
else{
gameLoseFour++;
}
break;
case'5':
if (rolledNumber == pointNumber)
{
gameWonFive++;
}
else{
gameLoseFive++;
}
break;
case'6':
if (rolledNumber == pointNumber)
{
gameWonSix++;
}
else
{
gameLoseSix++;
}
case'7':
case'8':
case'9':
case'10':
case'11':
case'12':
case'13':
case'14':
case'15':
case'16':
case'17':
case'18':
case'19':
case'20':
case'21':
case'22':
case'23':
case'24':
case'25':
case'26':
case'27':
case'28':
case'29':
case'30':
return 0;
}
totalNumberOfRolls = totalNumberOfRolls + numberOfRolls;
cout << gameHasBeenWon << " games won and " << gameHasBeenLost << " games lost on roll " << numberOfRolls << endl;
}
chanceOfWinning = ((double)gameHasBeenWon/(gameHasBeenWon + gameHasBeenLost));
cout << "The chances of winning are " << " = " << chanceOfWinning << endl;
double averageGame = 0;
cout << "The average game length is " << averageGame << " rolls." << endl;
cout << "Press any key to continue..." << endl;
return 0;
//create two vectors 1 for wins 1 for losses
//set the size of the vectors to 30
//set default value of each element to 0
std::vector<int> gameWon( 30 , 0 ) , gameLost( 30 , 0 );
int rolls = 1; //example roll could be what ever from your game
if( rolledNumber == pointNumber)
{
//increment the wins for that roll by 1
++gameWon[ rolls - 1 ]; //vectors start at index 0
} else {
--gameLost[ rolls - 1 ]; //decremented by 1 on loss
}
On another side note you may want to reconsider how you write your for loops. yeah for( totalNumberOfRolls=1; totalNumberOfRolls < 5501; totalNumberOfRolls++)
works.... but you should use the standard for loop for (variable = 0; variable < amount; ++variable ) {
so for yours it would be for( totalNumberOfRolls = 0; totalNumberOfRolls < 5500; ++totalNumberOfRolls ){
most people also use i or it for their value. Being an int or an iterator.
int gameWonOne =0;
int gameWonTwo =0;
int gameWonThree=0;
int gameWonFour=0;
int gameWonFive=0;
int gameWonSix=0;
int gameWonSeven=0;
int gameWonEight=0;
int gameWonNine =0;
int gameWonTen =0;
int gameWonEleven=0;
int gameWonTwelve=0;
int gameWonThirteen=0;
int gameWonFourteen=0;
int gameWonFifteen=0;
int gameWonSixteen=0;
int gameWonSevenTeen=0;
int gameWonEighteen=0;
int gameWonNinteen=0;
int gameWonTwenty=0;
int gameWonTwentyOne=0;
int gameWontTwentyTwo=0;
int gameWonTwentyThree=0;
int gameWontTwentyFour=0;
int gameWontTwentyFive=0;
int gameWonTwentySix=0;
int gameWonTwentySeven=0;
int gameWonTwentyEight =0;
int gameWontTwentyNine=0;
int gameWonThirty=0;
This is why god made arrays just so you know. And I think the problem is that dicetoss() has no implementation so there's nothing to keep track of. Didn't read beyond that in your code so fix it and will reply if you have more problems.