I am in the last part of the program and everything is working but one final thing. I need to get all the Subtotals, taxes, and total cost to add up....I tried using sums, counts, and change the variable names and still having trouble....this program has been a real pain

//Name: Bryan Kruep
//Class: CS 140-001
//Assignment: Lab 2
//Date: 01/22/08
#include <iostream>
#include <string>
using namespace std;
const double TACO_COST = 0.49;   
const double HOTDOG_COST = 0.75;
const double DRINKS_COST = 0.99;
const double SOURCREAM_COST = 0.15;
const double TAX_RATE = 0.0725;
int sum = 0;

int main ()
{

	int hotdogquantity = 0, tacoquantity = 0, sourcreamquantity = 0, drinkquantity = 0;
	double hotdogs_total_cost, tacos_total_cost, tacos_with_sourcream_total_cost, drinks_total_cost, subtotal, taxes, total_cost;
	char ans;
	int count = 1;

	cout << endl << "Programmed By: Bryan Kruep \n" <<endl;



	do
	{

	if (hotdogquantity >= 0)
{
	cout << "Number of Hotdogs: ";
	cin >> hotdogquantity;
}

while (hotdogquantity < 0)
{
	
cout << "Number of hotdogs cannot be a negative number!! Try again: ";
cin >> hotdogquantity;
}

if (tacoquantity >= 0)
{

	cout << "Number of Tacos: ";
	cin >> tacoquantity;
}

while (tacoquantity < 0)
{
cout << "Number of tacos cannot be a negative number!! Try again: ";
cin >> tacoquantity;
}

if (sourcreamquantity < tacoquantity)
{
	cout << "How many of those tacos with sour cream: ";
	cin >> sourcreamquantity;
}

while (sourcreamquantity > tacoquantity || sourcreamquantity < 0)
{

cout << "Can't have more tacos with sourcream than the number of tacos ordered. Number of sour creams cannot be a negative. Try again!: ";
cin >> sourcreamquantity;
}



if (drinkquantity >= 0)
{
	cout << "Number of drinks: ";
	cin >> drinkquantity;
}
while (drinkquantity < 0)
{
cout << "Number of drinks cannot be a negative number!! Try again: ";
cin >> drinkquantity;


}



	cout << endl << endl << endl << "BILL";
	cout << endl << "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _";
    
	cout << endl << "\t" << hotdogquantity << " Hotdogs"; 
	cout << endl << "\t" << tacoquantity << " Tacos" << " - " << sourcreamquantity << " with sour cream";
	cout << endl << "\t" << drinkquantity << " Drinks";
	
	//Calculate totals
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(2);
	hotdogs_total_cost = hotdogquantity * HOTDOG_COST;
	tacos_total_cost = tacoquantity * TACO_COST;
	tacos_with_sourcream_total_cost = sourcreamquantity * SOURCREAM_COST;
	drinks_total_cost = drinkquantity * DRINKS_COST;
	subtotal = hotdogs_total_cost + tacos_total_cost + tacos_with_sourcream_total_cost + drinks_total_cost;
	taxes = subtotal * TAX_RATE;
	total_cost = subtotal + taxes;

	//Display output
	cout << endl << endl << "Subtotal: " << subtotal;
	
	cout << endl << "Taxes: " << taxes;
	
	cout << endl << "Total: " << total_cost;
	
	cout << endl;
	

		sum = 0 ;
		cout << endl << "Another order? (Y/N)";
		cin >> ans;
		cout << endl << endl;

hotdogquantity = 0;
tacoquantity = 0;
sourcreamquantity = 0;
drinkquantity = 0;

 }while ( (ans != 'n') && (ans != 'N') );
new_total = subtotal + new_total;
new_taxes = taxes + new_taxes;
cout << "Total Day Receipts";
cout << endl << "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _";
cout << endl << endl << "Subtotal: " << new_total;
cout << endl << "Taxes: " << taxes;
cout << endl << "Total: " << total_cost;
cout << endl << endl;

	
return 0;
}

Consider where you would need to accumulate your overall subtotals and overall taxes. You need to accumulate each of these after each order.

you mean to say that when the user says 'no' to this "cout << endl << "Another order? (Y/N)";" you want to add up those numbers for the entire user order..rt?

for the correct way of doing this lets first put everything inside the while loop first.

while ( (ans != 'n') && (ans != 'N')

put everything inside this loop.. you dont need to ask this in the end... just initialise 'ans' with a ''. at the end of the loop, ask the user if he wants to enter more orders.. if yes then it'll loop or else you will come out of the loop and sum the numbers. use member variables or local variables(but declared outside the while loop) for storing the cost etc..

I tried that and still isnt givin me the right totals....this thing is really drivin me crazy!!!!!

//Name: Bryan Kruep
//Class: CS 140-001
//Assignment: Lab 2
//Date: 01/22/08
#include <iostream>
#include <string>
using namespace std;
const double TACO_COST = 0.49;   
const double HOTDOG_COST = 0.75;
const double DRINKS_COST = 0.99;
const double SOURCREAM_COST = 0.15;
const double TAX_RATE = 0.0725;
int sum = 0;

int main ()
{

	int hotdogquantity = 0, tacoquantity = 0, sourcreamquantity = 0, drinkquantity = 0;
	double hotdogs_total_cost, tacos_total_cost, tacos_with_sourcream_total_cost, drinks_total_cost, subtotal, taxes, total_cost,new_total = 0, new_taxes = 0;
	char ans;
	int count = 1;

	cout << endl << "Programmed By: Bryan Kruep \n" <<endl;



	do
	{

	if (hotdogquantity >= 0)
{
	cout << "Number of Hotdogs: ";
	cin >> hotdogquantity;
}

while (hotdogquantity < 0)
{
	
cout << "Number of hotdogs cannot be a negative number!! Try again: ";
cin >> hotdogquantity;
}

if (tacoquantity >= 0)
{

	cout << "Number of Tacos: ";
	cin >> tacoquantity;
}

while (tacoquantity < 0)
{
cout << "Number of tacos cannot be a negative number!! Try again: ";
cin >> tacoquantity;
}

if (sourcreamquantity < tacoquantity)
{
	cout << "How many of those tacos with sour cream: ";
	cin >> sourcreamquantity;
}

while (sourcreamquantity > tacoquantity || sourcreamquantity < 0)
{

cout << "Can't have more tacos with sourcream than the number of tacos ordered. Number of sour creams cannot be a negative. Try again!: ";
cin >> sourcreamquantity;
}



if (drinkquantity >= 0)
{
	cout << "Number of drinks: ";
	cin >> drinkquantity;
}
while (drinkquantity < 0)
{
cout << "Number of drinks cannot be a negative number!! Try again: ";
cin >> drinkquantity;


}



	cout << endl << endl << endl << "BILL";
	cout << endl << "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _";
    
	cout << endl << "\t" << hotdogquantity << " Hotdogs"; 
	cout << endl << "\t" << tacoquantity << " Tacos" << " - " << sourcreamquantity << " with sour cream";
	cout << endl << "\t" << drinkquantity << " Drinks";
	
	//Calculate totals
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(2);
	hotdogs_total_cost = hotdogquantity * HOTDOG_COST;
	tacos_total_cost = tacoquantity * TACO_COST;
	tacos_with_sourcream_total_cost = sourcreamquantity * SOURCREAM_COST;
	drinks_total_cost = drinkquantity * DRINKS_COST;
	subtotal = hotdogs_total_cost + tacos_total_cost + tacos_with_sourcream_total_cost + drinks_total_cost;
	taxes = subtotal * TAX_RATE;
	total_cost = subtotal + taxes;

	//Display output
	cout << endl << endl << "Subtotal: " << subtotal;
	
	cout << endl << "Taxes: " << taxes;
	
	cout << endl << "Total: " << total_cost;
	
	cout << endl;
	

		sum = 0 ;
		cout << endl << "Another order? (Y/N)";
		cin >> ans;
		cout << endl << endl;

hotdogquantity = 0;
tacoquantity = 0;
sourcreamquantity = 0;
drinkquantity = 0;
	
}
	while ( (ans != 'n') && (ans != 'N') );	
	{	
new_total = subtotal + new_total;
new_taxes = taxes + new_taxes;
cout << "Total Day Receipts";
cout << endl << "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _";
cout << endl << endl << "Subtotal: " << new_total;
cout << endl << "Taxes: " << taxes;
cout << endl << "Total: " << total_cost;
cout << endl << endl;
	}


	
return 0;
}

oops forgot code tags one sec

//Name: Bryan Kruep
//Class: CS 140-001
//Assignment: Lab 2
//Date: 01/22/08
#include <iostream>
#include <string>
using namespace std;
const double TACO_COST = 0.49;   
const double HOTDOG_COST = 0.75;
const double DRINKS_COST = 0.99;
const double SOURCREAM_COST = 0.15;
const double TAX_RATE = 0.0725;
int sum = 0;

int main ()
{

	int hotdogquantity = 0, tacoquantity = 0, sourcreamquantity = 0, drinkquantity = 0;
	double hotdogs_total_cost, tacos_total_cost, tacos_with_sourcream_total_cost, drinks_total_cost, subtotal, taxes, total_cost,new_total = 0, new_taxes = 0;
	char ans;
	int count = 1;

	cout << endl << "Programmed By: Bryan Kruep \n" <<endl;



	do
	{

	if (hotdogquantity >= 0)
{
	cout << "Number of Hotdogs: ";
	cin >> hotdogquantity;
}

while (hotdogquantity < 0)
{
	
cout << "Number of hotdogs cannot be a negative number!! Try again: ";
cin >> hotdogquantity;
}

if (tacoquantity >= 0)
{

	cout << "Number of Tacos: ";
	cin >> tacoquantity;
}

while (tacoquantity < 0)
{
cout << "Number of tacos cannot be a negative number!! Try again: ";
cin >> tacoquantity;
}

if (sourcreamquantity < tacoquantity)
{
	cout << "How many of those tacos with sour cream: ";
	cin >> sourcreamquantity;
}

while (sourcreamquantity > tacoquantity || sourcreamquantity < 0)
{

cout << "Can't have more tacos with sourcream than the number of tacos ordered. Number of sour creams cannot be a negative. Try again!: ";
cin >> sourcreamquantity;
}



if (drinkquantity >= 0)
{
	cout << "Number of drinks: ";
	cin >> drinkquantity;
}
while (drinkquantity < 0)
{
cout << "Number of drinks cannot be a negative number!! Try again: ";
cin >> drinkquantity;


}



	cout << endl << endl << endl << "BILL";
	cout << endl << "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _";
    
	cout << endl << "\t" << hotdogquantity << " Hotdogs"; 
	cout << endl << "\t" << tacoquantity << " Tacos" << " - " << sourcreamquantity << " with sour cream";
	cout << endl << "\t" << drinkquantity << " Drinks";
	
	//Calculate totals
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(2);
	hotdogs_total_cost = hotdogquantity * HOTDOG_COST;
	tacos_total_cost = tacoquantity * TACO_COST;
	tacos_with_sourcream_total_cost = sourcreamquantity * SOURCREAM_COST;
	drinks_total_cost = drinkquantity * DRINKS_COST;
	subtotal = hotdogs_total_cost + tacos_total_cost + tacos_with_sourcream_total_cost + drinks_total_cost;
	taxes = subtotal * TAX_RATE;
	total_cost = subtotal + taxes;

	//Display output
	cout << endl << endl << "Subtotal: " << subtotal;
	
	cout << endl << "Taxes: " << taxes;
	
	cout << endl << "Total: " << total_cost;
	
	cout << endl;
	

		sum = 0 ;
		cout << endl << "Another order? (Y/N)";
		cin >> ans;
		cout << endl << endl;

hotdogquantity = 0;
tacoquantity = 0;
sourcreamquantity = 0;
drinkquantity = 0;
	
}
	while ( (ans != 'n') && (ans != 'N') );	
	{	
new_total = subtotal + new_total;
new_taxes = taxes + new_taxes;
cout << "Total Day Receipts";
cout << endl << "_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _";
cout << endl << endl << "Subtotal: " << new_total;
cout << endl << "Taxes: " << taxes;
cout << endl << "Total: " << total_cost;
cout << endl << endl;
	}


	
return 0;
}

nvm figured it out

dont put everything in main. write separate functions to perform different operations. that way your code will b more modular and easy to maitain and make changes.

n i didnt check.. the do-while loop is not used like this .. please check the correct way of using it ...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.