Dice program question.

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.


#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
int die_1=0, die_2=0, total_score1, total_score2, player1score;
char enter;

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";
cin>>enter;
srand(time(0));
if((enter = 's') || (enter = 'S'))
{
do
{
die_1 = (rand() % 6) +1;
die_2 = (rand() % 6) +1;
total_score1 = die_1 + die_2;
player1score = total_score1;
cout<<total_score1<<endl;
}while((total_score1 != 7) && (total_score1 != 11));
cout<<"Player score is: "<<player1score<<endl;
}

return 0;
}
I just posted a dice-game program that might give you some ideas.
http://cplusplus.com/forum/beginner/93084/

And please use [ code ] and [ /code ] to make your code more readable.
Thanks and I really just need an equation that will allow me to store all of the values of total_score1 that appear in the while loop.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
        int die_1=0, die_2=0, total_score1, total_score2, player1score;
        char enter;

        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";
        cin>>enter;
        srand(time(0));
        if((enter = 's') || (enter = 'S'))
        {
                do
                {
                        die_1 = (rand() % 6) +1;
                        die_2 = (rand() % 6) +1;
                        total_score1 = die_1 + die_2;
                        player1score = total_score1;
                        cout<<total_score1<<endl;
                }while((total_score1 != 7) && (total_score1 != 11));
                cout<<"Player score is: "<<player1score<<endl;
        }

        return 0;
}


Here's what my code looks like in a readable format. Thanks for the info. I'm new.
Topic archived. No new replies allowed.