Extracting from loops

so i have a loop that will run x number of times and each time it will produce a prize which is a certain sum of money. I need to a way to sum all the money earned. I am thinking there should be a way to extract the prize one for each time the loop runs but i am not sure how to do that. if anybody could help thatd be great!

#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
using namespace std;

int main()
{
cout <<"Option A: Drop one chip into one slot" << endl;
cout <<"Option B: Drop multiple chips into one slot" << endl;
cout <<"Option C: Quite the program"<< endl;
cout <<"Select and option: ";
string user_choice;
cin >> user_choice;
int slot;
double location;
int chip_number;

if (user_choice == "A")
{
cout <<"Select a slot number (0-8) to drop your coin: ";
cin >> slot;

if (0<= slot && slot < 9)
{
int x=1;
location = slot;

for (x=1; x<=12; x++)
{
double r = rand()%(2)-.5;

if (location == 8)
{ location = location - .5;
}
else if (location==0)
{
location = location + .5;
}

else if (location >= .5 && location <= 7.5)
{
location = location + r;
}

cout << location << endl;

}

if ( location ==0 )
{
cout << "Prize: $100" << endl;
}
if (location == 1)
{
cout << "Prize: $500" << endl;
}
if (location == 2)
{
cout << "Prize: $1000" << endl;
}
if (location == 3)
{
cout << "Prize: $0" << endl;
}
if (location == 4)
{
cout << "Prize: $10,000" << endl;
}
if (location == 5)
{
cout << "Prize: $0" << endl;
}
if (location == 6)
{
cout << "Prize: $1000" << endl;
}
if (location == 7)
{
cout << "Prize: $500" << endl;
}
if (location == 8)
{
cout << "Prize: $100" << endl;
}
}


}
else if ( user_choice == "B" )
{
cout << "Enter the number of chips you would like to play: ";
cin >> chip_number;
cout <<"Select a slot number (0-8) to drop your coin: ";
cin >> slot;

if (0<= slot && slot < 9)
{
int x=1;
location = slot;
int y =1;
int prize;

for (y=1; y<=chip_number ; y++)

{
for (x=1; x<=12; x++)
{
double r = rand()%(2)-.5;

if (location == 8)
{ location = location - .5;
}
else if (location==0)
{
location = location + .5;
}

else if (location >= .5 && location <= 7.5)
{
location = location + r;
}

cout << location << endl;

}

if ( location ==0 )
{
cout << "Prize: $100" <<endl;
prize = 100;
}
if (location == 1)
{
cout << "Prize: $500" <<endl;
prize = 500;
}
if (location == 2)
{
cout << "Prize: $1000" <<endl;
prize = 1000;
}
if (location == 3)
{
cout << "Prize: $0" <<endl;
prize = 0;
}
if (location == 4)
{
cout << "Prize: $10,000" <<endl;
prize = 10000;
}
if (location == 5)
{
cout << "Prize: $0" <<endl;
prize =0;
}
if (location == 6)
{
cout << "Prize: $1000" <<endl;
prize =1000;
}
if (location == 7)
{
cout << "Prize: $500" <<endl;
prize = 500;
}
if (location == 8)
{
cout << "Prize: $100" <<endl;
prize = 100;
}
cout <<endl;
}
cout << prize + prize <<endl;
}


}
return 0;
}
Instead of just printing the prize number, try adding it to a variable you are using to store the sum.
perfect thanks!
Topic archived. No new replies allowed.