Need help with a running total

So basically i need to keep a running total of the amount of tickets, single and return ticket, amount of stops and the total price.
Any help would be greatly appreciated.

::::::::: This is where you enter the amount of tickets and the other things.

cout<<"\nPlease enter the number of adults ('0' if none):> ";
cin>>adult;
cout<<"\nPlease enter the number of children ('0' if none):> ";
cin>>children;
cout<<"\nPlease enter the number of seniors ('0' if none):> ";
cin>>senior;
cout<<"\nPlease enter the number of families ('0' if none):> ";
cin>>family;
cout<<"\nEnter 1 if return ticket ('0' if not) :> ";
cin>>Return;
cout<<"\nEnter 1 if single ticket ('0' if not) :> ";
cin>>Single;
cout<<"\nPlease enter the amount of stops: ";
cin>>stop;
}
float calcPrice(int adults, int children, int seniors, int families,
int Single,int Return, int stop)
{
float totalCost;

costAdult = adults*adultsPrice;
costChild = children*childrenPrice;
costSenior = seniors*seniorPrice;
costFamily = families*familyPrice;

totalCost = (costAdult+costChild+costSenior+costFamily) * stop;
cout<< " " << endl;

costSingle = totalCost;
costReturn = totalCost * 2 * 0.85;
if (Return == 1)

return costReturn;
else
return costSingle;

::::::::::::::::::: I need the running total of them to be kept here:::::::::::
"\nAmount of adult tickets: " << endl;
cin>>adulttotal;
cout << "\nAmount of children tickets: " << endl;
cin>>childrentotal;
cout << "\nAmount of senior tickets: " << endl;
cin>>seniortotal;
cout << "\nAmount of family tickets: " << endl;
cin>>familytotal;
cout << "\nAmount of single tickets: " << endl;
cin>>singletotal;
cout << "\nAmount of return tickets: " << endl;
cin>>returntotal;
cout << "\nTotal: " << endl;
cin>>pricetotal;
break;

[Full Code]

#include <iostream>
#include <string>
#include <Windows.h>

const float adultsPrice = 0.75, childrenPrice = 0.30, seniorPrice = 0.35,
familyPrice = 1.60, returnPrice = 0.85;
float totalCost;
int adults, children, seniors, families, Single,Return,stop,
adulttotal,childrentotal,seniortotal,familytotal,singletotal,returntotal,pricetotal;
float costAdult, costChild, costSenior, costFamily, costReturn, costSingle;
int choice = 0;
using namespace std;

void getQuantity(int &adult, int &child, int &senior, int &family,
int &Single, int &Return, int &stops);

float calcPrice(int adults, int children, int seniors, int families,
int Single, int Return, int stop);

int main()
{
string username;
string password;

cout << "Please choose from the menu below" << endl;
do{
cout<< " " << endl;
cout << "1. Log-in" << endl;
cout<< " " << endl;
cout << "2. Help" << endl;
cout<< " " << endl;
cout << "3. Ticket System" << endl;
cout<< " " << endl;
cout << "4. Report" << endl;
cout<< " " << endl;
cout << "5. Exit" << endl;
cout<< " " << endl;
cin >> choice;



switch (choice)
{
case 1:
do
{
cout << "Enter the Username: ";
cin >> username;

cout << "Enter the Password: ";
cin >> password;
}
while(password !="123Odus");
cout<<"Username and Password are correct"<<endl;
cout<< " " << endl;
break;
case 2:
system("start winword E:\Help.docx");
break;
case 3:
if (password != "123Odus")
{
cout<<"Please enter log-in details"<<endl;
}
else
{
cout << "Odus Ticketing now online" << endl;
getQuantity(adults,children,seniors,families,Single,Return,stop);
totalCost=calcPrice(adults,children,seniors,families,Single,Return
,stop);
cout<<"Total cost: "<<totalCost<<endl;
}
break;
case 4:
cout << "Odus Report" << endl;
cout<< " " << endl;
cout << "\nAmount of adult tickets: " << endl;
cin>>adulttotal;
cout << "\nAmount of children tickets: " << endl;
cin>>childrentotal;
cout << "\nAmount of senior tickets: " << endl;
cin>>seniortotal;
cout << "\nAmount of family tickets: " << endl;
cin>>familytotal;
cout << "\nAmount of single tickets: " << endl;
cin>>singletotal;
cout << "\nAmount of return tickets: " << endl;
cin>>returntotal;
cout << "\nTotal: " << endl;
cin>>pricetotal;
break;
case 5:
cout << "Odus closed" << endl;
}
}while (choice != 5);





}

void getQuantity(int &adult, int &children, int &senior, int &family,
int &Single, int &Return, int &stop)
{
cout<<"\nPlease enter the number of adults ('0' if none):> ";
cin>>adult;
cout<<"\nPlease enter the number of children ('0' if none):> ";
cin>>children;
cout<<"\nPlease enter the number of seniors ('0' if none):> ";
cin>>senior;
cout<<"\nPlease enter the number of families ('0' if none):> ";
cin>>family;
cout<<"\nEnter 1 if return ticket ('0' if not) :> ";
cin>>Return;
cout<<"\nEnter 1 if single ticket ('0' if not) :> ";
cin>>Single;
cout<<"\nPlease enter the amount of stops: ";
cin>>stop;
}
float calcPrice(int adults, int children, int seniors, int families,
int Single,int Return, int stop)
{
float totalCost;

costAdult = adults*adultsPrice;
costChild = children*childrenPrice;
costSenior = seniors*seniorPrice;
costFamily = families*familyPrice;

totalCost = (costAdult+costChild+costSenior+costFamily) * stop;
cout<< " " << endl;

costSingle = totalCost;
costReturn = totalCost * 2 * 0.85;
if (Return == 1)

return costReturn;
else
return costSingle;
}

[/code]
closed account (j3Rz8vqX)
I see lots of functions.

You choice: Global variables or passing local variables.

After that, you simply process accumulations of the certain variable whenever it needs to be accumulated.

Tip:
Ensure your declaration of the total variables are properly initialized; garbage + value = garbage.
So you mean: adulttotal = adult + adult?

I'm abit confused as you can tell....
closed account (j3Rz8vqX)
Underscore:
adult_total = adult_total + adult;

Camelcase:
adultTotal = adultTotal + adult;

Edit:
Expansion:

Let's say:

Round 1: adult_total was 0.
5 = 0 + 5;

Round 1: adult_total was 5.
12 = 5 + 7;

Round 1: adult_total was 12.
19 = 12 + 7;

...

Round 100: adult_total was 217.
210 = 217 + 3;

Last edited on
Still can find a solution. Think i may be putting it in the wrong place ;)
Topic archived. No new replies allowed.