I'm having a problem adding up the values of the dice rolls in a while loop. The program will only store the last value so how would I get it to store multiples values? Here is my program thus far. I would try an array but we haven't gotten to that yet.
int die_1=0, die_2=0, total_score1, total_score2, player1score;
cout<<"Welcome to the dice game. The rules are as follows: \n";
cout<<"1. Roll the two dice and add up the total. \n";
cout<<"2. If you roll a 7 or an 11, your turn is over and it is now the other players turn. \n";
cout<<"3. If the other player rolls a 7 or an 11, then the scores are tallied and the player with the highest score wins.\n";
cout<<"Enter the letter s and press enter to roll.\n";
if((enter = 's') || (enter = 'S'))
die_1 = (rand() % 6) +1;
die_2 = (rand() % 6) +1;
total_score1 = die_1 + die_2;
player1score = total_score1;
}while((total_score1 != 7) && (total_score1 != 11));
cout<<"Player score is: "<<player1score<<endl;
Anyone know what operators or equation I should use to accomplish this?
You got two responses. One of them was a possible solution, however you didn't respond to it to say either "How would I do that?" or "I don't understand." Instead, you ignored it and reposted your question.
We can see that over the course of the time you've been asking this question, your code has not changed at all, suggesting that you aren't actually working on the problem. Just hoping for an answer.
Some people search for answers prior to posting (and I don't know whether you did or not, it's beside the point) and when they do so, it is helpful if they don't come up with answers strewn across three threads, so please stick with your original thread in the future. There isn't any stigma associated with bumping a post here, unless it's done excessively.
I didn't reply to the answers given which was a mistake and I thank you for pointing that out but I have worked on my code a little. quick question?
What effect does "std" have on the code and when I tried the += function on my program I kept getting a strange value. I can post what it gave me. I tried that before I posted the question so I just went back to what I had.
Welcome to the dice game. The rules are as follows:
1. Roll the two dice and add up the total.
2. If you roll a 7 or an 11, your turn is over and it is now the other players turn.
3. If the other player rolls a 7 or an 11, then the scores are tallied and the player with the highest score wins.
Enter the letter s and press enter to roll.
Player score is: 6471695
Oh ok thank you. That fixed my problem. Setting it to 0 before everything else made the program work. Thank you and sorry if I was rude for reposting and ignoring the other answers I got. I'll remember what and what not to do.