I have created a program allows you to input the amount of items purchased, and then input the price of each item and the sales tax. It then creates a receipt which totals all the prices and sales tax.

Now I want to be able to list the items and their prices in the sales receipt as well. What would I have to do so lets say you pick 5 items and type in 5 prices and it give you the sales receipt, before it tells you the total, I want it to list the 5 items so looks like this:

Sales Receipt

Item 1: Price
Item 2: Price
Item 3: Price
Item 4: Price
Item 5: Price

**********

(rest of sales receipt)

Here is what I have so far:

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
char rerun;

		do //The do-while for a program rerun option
		{

// Declare variables: counter, items, sales items, sales total, sales tax, and grand total
int items, count;
int * price;
double total, percent, g_t, tax;

// Input information
	cout<<"How many sales items do you have? :";
	cin>>items;

	price= new (nothrow) int[items];
	if (price == 0)
		cout << "error";
	else
	{
			for (count = 0; count < items; count++)
			{
				cout<<"Enter the value of the sales item. : $";
				cin>>price[count];
				total = total + price;
			}
	}
		
	cout << endl << endl;

	cout<<"Enter in the sales tax percentage. :";
	cin>>percent;
		
		tax = total * (percent/100);
		g_t = tax + total;
		
	cout << endl << endl;
		
	cout << "********************************************" << endl;
	cout << "********  S A L E S  R E C E I P T  ********" << endl;
	cout << "********************************************" << endl;
	cout << "**                                        **" << endl;
	cout << "**                                        **" << endl;
	cout << "entered";
	for (count = 0; count < items; count++)
		cout << price[count] << endl;
	cout << "**                                        **" << endl;
	cout << "**                                        **" << endl;
	cout << setiosflags(ios::fixed) << setprecision(2);
	cout << "**  Total Sales:    $" << setw(9) << total << "            **" << endl;
	cout << "**  Sales Tax:      $" << setw(9) << tax << "            **" << endl;
	cout << "**                  -----------           **" << endl;
	cout << "**  Grand Total:    $" << setw(9) << g_t << "            **" << endl;
	cout << "**                                        **" << endl;
	cout << "**                                        **" << endl;
	cout << "********************************************" << endl;
		
	cout << endl << endl;

		cout<<"Do you want to run this program again? (y/n)";
		cin>>rerun;
			
		}

	while (rerun == 'y' || rerun == 'Y');
	
	system ("PAUSE");
	return 0;
} //End Main Function

I receive the following error:

salerec.cpp(33) : error C2111: pointer addition requires integral operand
Error executing cl.exe.

salerec.exe - 1 error(s), 0 warning(s)

How should I be writing it so that an operator is used on a pointer?

line 29 should be total = total + price[count]; . What total = total + price does is say add total to the address of the first element in prince and then store it in total. You cant do that because total is a double. What I did say to add the price entered with total and store the result back in total,

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
char rerun;

		do //The do-while for a program rerun option
		{

// Declare variables: counter, items, sales items, sales total, sales tax, and grand total
int items, count;
int * price;
double total, percent, g_t, tax;

// Input information
	cout<<"How many sales items do you have? :";
	cin>>items;

	price= new (nothrow) int[items];
	if (price == 0)
		cout << "error";
	else
	{
			for (count = 0; count < items; count++)
			{
				cout<<"Enter the value of the sales item. : $";
				cin>>price[count];
				total = total + price[count];
			}
	}
		
	cout << endl << endl;

	cout<<"Enter in the sales tax percentage. :";
	cin>>percent;
		
		tax = total * (percent/100);
		g_t = tax + total;
		
	cout << endl << endl;
		
	cout << "********************************************" << endl;
	cout << "********  S A L E S  R E C E I P T  ********" << endl;
	cout << "********************************************" << endl;
	cout << "**                                        **" << endl;
	cout << "**                                        **" << endl;
	for (count = 0; count < items; count++)
		cout << price[count] << endl;
	cout << "**                                        **" << endl;
	cout << "**                                        **" << endl;
	cout << setiosflags(ios::fixed) << setprecision(2);
	cout << "**  Total Sales:    $" << setw(9) << total << "            **" << endl;
	cout << "**  Sales Tax:      $" << setw(9) << tax << "            **" << endl;
	cout << "**                  -----------           **" << endl;
	cout << "**  Grand Total:    $" << setw(9) << g_t << "            **" << endl;
	cout << "**                                        **" << endl;
	cout << "**                                        **" << endl;
	cout << "********************************************" << endl;
		
	cout << endl << endl;

		cout<<"Do you want to run this program again? (y/n)";
		cin>>rerun;
			
		}

	while (rerun == 'y' || rerun == 'Y');
	
	system ("PAUSE");
	return 0;
} //End Main Function

Fixed it. The prices are now being displayed except it screwed up everything else in the display.

[img]http://i44.servimg.com/u/f44/16/74/15/46/output10.jpg[/img]

It should be like this:
[img]http://i44.servimg.com/u/f44/16/74/15/46/output11.jpg[/img]

That is because you are displaying garbage values and since you are using ios::fixed it is displaying the entire value without an exponent.

That is because you are displaying garbage values and since you are using ios::fixed it is displaying the entire value without an exponent.

That made absolutely no sense! Sorry, I'm still learning a lot as I go.

I set total = 0 which fixed the problem.

However, I still cannot get the sales receipt portion to look the way I need to. It seems I cannot simply just add a cout and sales items there. How would I get it so that it automatically lists the number of items with the price. right now only the price is being listed.

[EDIT]disregard[/EDIT]

I want to number my items. I want it to ask "Input sales item 1" "Input sales item 2" "Input sales item 3" and then on the receipt I want it to do the same thing:

Sale item 1: $(price)
Sale item 2: $(price)
Sale item 3: $(price)

I want those number to show up. I can't find any tutorials or anything to read that teaches how to number items either.

Here is my current code:

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
char rerun;

		do //The do-while for a program rerun option
		{

// Declare variables: counter, items, sales items, sales total, sales tax, and grand total
int items, count;
int * price;
double total = 0, percent, g_t, tax;

// Input information
	cout<<"How many sales items do you have? :";
	cin>>items;

	price= new (nothrow) int[items];
	if (price == 0)
		cout << "error";
	else
	{
			for (count = 0; count < items; count++)
			{
				cout<<"Enter the value of the sales item: $";
				cin>>price[count];
				total = total + price[count];
			}
	}
		
	cout << endl << endl;

	cout<<"Enter in the sales tax percentage: ";
	cin>>percent;
		
		tax = total * (percent/100);
		g_t = tax + total;
		
	cout << endl << endl;

	cout << "********************************************" << endl;
	cout << "********  S A L E S  R E C E I P T  ********" << endl;
	cout << "********************************************" << endl;
	cout << "**                                        **" << endl;
	cout << "**                                        **" << endl;
	for (count = 0; count < items; count++)
		cout << "**  Sales Item #:    $" << setw(9) << setprecision(2) << price[count] << "           **" << endl;
	cout << "**                                        **" << endl;
	cout << "**                                        **" << endl;
	cout << "********************************************" << endl;
	cout << "**                                        **" << endl;
	cout << "**                                        **" << endl;
	cout << setiosflags(ios::fixed) << setprecision(2);
	cout << "**  Total Sales:    $" << setw(9) << total << "            **" << endl;
	cout << "**  Sales Tax:      $" << setw(9) << tax << "            **" << endl;
	cout << "**                  -----------           **" << endl;
	cout << "**  Grand Total:    $" << setw(9) << g_t << "            **" << endl;
	cout << "**                                        **" << endl;
	cout << "**                                        **" << endl;
	cout << "********************************************" << endl;
		
	cout << endl << endl;

		cout<<"Do you want to run this program again? (y/n)";
		cin>>rerun;
			
		}

	while (rerun == 'y' || rerun == 'Y');
	
	system ("PAUSE");
	return 0;
} //End Main Function

if you want to display a number try doing this to your for loop.

for (count = 0; count < items; count++)
		cout << "**  Sales Item " << count + 1 << ":    $" << setw(9) << setprecision(2) << price[count] << "           **" << endl;

You can split up your output almost any way you want to

That worked like a charm!

I found one big issue! I cannot input decimal value for the price of an item. I know this is because price is set to integer. I need to be able to use decimal values for the price. Previously I used double for price but to create the dynamic array, I changed it to integer.

What options are there? Or what can I do? The entire program just stops working as soon as I input decimals into the sales item price such 10.50.

To store the prices as doubles, just make them doubles.

Declare your price pointer as:

double * price;

And allocate an array of doubles:

price= new double[items];

You don't have to change anything else (that I can see).

that did the trick! I need to learn to read all of my code and make the proper changes. I changed it to double in the variable but not at the latter part of the code.

I have one last component of this program now. I want to be able to name the sales item such as book, pen, car, etc. and then in the sales receipt, instead of it listing the items as Sales Item 1, Sales Item 2, etc. I want it to be listed (name of item): Price so like Book: Price, Pen: Price, and etc.

I know this goes back into memory and storing it all but it seems a little more complex.

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
char rerun;

		do //The do-while for a program rerun option
		{

// Declare variables: counter, items, sales items, sales total, sales tax, and grand total
int items, count;
double * price; // creates the array to store the price
double total = 0, percent, g_t, tax;

// Input information
	cout<<"How many sales items do you have? :";
	cin>>items;

	price= new (nothrow) double[items];
	if (price == 0)
		cout << "error";
	else
	{
			for (count = 0; count < items; count++)
			{
				cout<<"Enter the value of the sales item " << count + 1 << ": $";
				cin>>price[count];
				total = total + price[count];
			}
	}
		
	cout << endl << endl;

	cout<<"Enter in the sales tax percentage: ";
	cin>>percent;
		
		tax = total * (percent/100);
		g_t = tax + total;
		
	cout << endl << endl;

	cout << "********************************************" << endl;
	cout << "********  S A L E S  R E C E I P T  ********" << endl;
	cout << "********************************************" << endl;
	cout << "**                                        **" << endl;
	cout << "**                                        **" << endl;
	cout << setiosflags(ios::fixed) << setprecision(2);
	for (count = 0; count < items; count++)
		cout << "**  Sales Item " << count + 1 << ":   $" << setw(9) << price[count] << "            **" << endl;
	delete[] price; // clears the memory
	cout << "**                                        **" << endl;
	cout << "**                                        **" << endl;
	cout << "********************************************" << endl;
	cout << "**                                        **" << endl;
	cout << "**                                        **" << endl;
	cout << "**  Total Sales:    $" << setw(9) << total << "            **" << endl;
	cout << "**  Sales Tax:      $" << setw(9) << tax << "            **" << endl;
	cout << "**                  -----------           **" << endl;
	cout << "**  Grand Total:    $" << setw(9) << g_t << "            **" << endl;
	cout << "**                                        **" << endl;
	cout << "**                                        **" << endl;
	cout << "********************************************" << endl;
		
	cout << endl << endl;

		cout<<"Do you want to run this program again? (y/n)";
		cin>>rerun;
			
		}

	while (rerun == 'y' || rerun == 'Y');
	
	system ("PAUSE");
	return 0;
} //End Main Function

You have two choices, 1) you create a second array of std::string on the side and populate and print it pretty much the same way as you do with the "prices" array, or 2) you create a structure that contains both a price and a name, and create an array of that instead of the two separate ones.

In the first option, you can simply create an array of std::strings (#include <string> at the top), and do this where you allocate the price array:

string* names = new string[items];

And then, input the names like so:

cout << "Enter the name of the sales item " << count + 1 << ": ";
      cin >> names[count];
      cout << "Enter the value of '" << names[count] << "': $";
      //.. as before

And similarly for printing it at the end.

I went with the way I already had but it is producing errors

#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
char rerun;

		do //The do-while for a program rerun option
		{

// Declare variables: counter, items, sales items, sales total, sales tax, and grand total
int items, count;
double * price; // creates the array to store the price
double total = 0, percent, g_t, tax;
string * names = new string[items];

// Input information
	cout<<"How many sales items do you have? :";
	cin>>items;
	
	// Input and storage of items names
	names = new (nothrow) string[items];
	if (names == 0)
		cout << "error names";
	else
	{
		for (count = 0; count < items; count++)
		{
			cout << "Enter the name of the sales item " << count + 1 << ": ";
			cin >> names[count];
		}
	}

	// Input and storage of items prices
	price = new (nothrow) double[items];
	if (price == 0)
		cout << "error";
	else
	{
			for (count = 0; count < items; count++)
			{
				cout<<"Enter the value of the sales item " << count + 1 << ": $";
				cin>>price[count];
				total = total + price[count];
			}
	}
		
	cout << endl << endl;

	cout<<"Enter in the sales tax percentage: ";
	cin>>percent;
		
		tax = total * (percent/100);
		g_t = tax + total;
		
	cout << endl << endl;

	cout << "********************************************" << endl;
	cout << "********  S A L E S  R E C E I P T  ********" << endl;
	cout << "********************************************" << endl;
	cout << "**                                        **" << endl;
	cout << "**                                        **" << endl;
	cout << setiosflags(ios::fixed) << setprecision(2);
	for (count = 0; count < items; count++)
		cout << "**  Sales Item " << count + 1 << ":   $" << setw(9) << price[count] << "            **" << endl;
	delete[] price; // clears the memory
	cout << "**                                        **" << endl;
	cout << "**                                        **" << endl;
	cout << "********************************************" << endl;
	cout << "**                                        **" << endl;
	cout << "**                                        **" << endl;
	cout << "**  Total Sales:    $" << setw(9) << total << "            **" << endl;
	cout << "**  Sales Tax:      $" << setw(9) << tax << "            **" << endl;
	cout << "**                  -----------           **" << endl;
	cout << "**  Grand Total:    $" << setw(9) << g_t << "            **" << endl;
	cout << "**                                        **" << endl;
	cout << "**                                        **" << endl;
	cout << "********************************************" << endl;
		
	cout << endl << endl;

		cout<<"Do you want to run this program again? (y/n)";
		cin>>rerun;
			
		}

	while (rerun == 'y' || rerun == 'Y');
	
	system ("PAUSE");
	return 0;
} //End Main Function

Errors I receive

:\Users\Neel P\Documents\Classes\Summer 2011\CMPSC 101\HW6\salesname.cpp(26) : warning C4291: 'void *__cdecl operator new(unsigned int,const struct std::nothrow_t &)' : no matching operator delete found; memory will not be freed if initialization throws an exception

c:\program files (x86)\microsoft visual studio\vc98\include\new(36) : see declaration of 'new' salesname.cpp(34) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<
char> >' (or there is no acceptable conversion)

First, you need to include <string> at the top, like I mentioned in the previous post. And this is what causes the error.

Second, you cannot allocate the array of strings before you know the size of the array.

Third, you should always prefer to declare variables where they are first used. This will help catch mistakes like I just mentioned (if "items" doesn't exist yet, you don't run into the danger of using it before it has been initialised).

Finally, you need to match every new statement with a delete statement when you are done with the array (that is what the compilation warning is about).

Correct indentation is also a big help for you and us.

So, with those small modifications, you get:

#include <iostream>
#include <iomanip>
#include <string> //include <string> in order to use the std::string class.

using namespace std;

int main()
{
  
  do //The do-while for a program rerun option
  {
    
    // Input information
    int items = 0;
    cout<<"How many sales items do you have? :";
    cin>>items;
	
    // Input and storage of items
    string* names = new (nothrow) string[items];
    if (names == 0) {
      cout << "Error: could not allocate the names array!" << endl;
      return 2; //terminate because you cannot recover from this problem.
    };

    double* price = new (nothrow) double[items];
    if (price == 0) {
      cout << "Error: could not allocate the price array!" << endl;
      return 1; //terminate because you cannot recover from this problem.
    };

    double total = 0;
    for (int count = 0; count < items; count++)
    {
      cout << "Enter the name of the sales item " << count + 1 << ": ";
      cin >> names[count];
      cout << "Enter the value of the sales item '" << names[count] << "': $";
      cin >> price[count];
      cin.ignore(); //remove stray input characters (new-line character).
      total += price[count];
    }
    
    cout << endl << endl;

    double percent = 0.0;
    cout << "Enter in the sales tax percentage: ";
    cin >> percent;
		
    double tax = total * (percent / 100);
    double g_t = tax + total;

    cout << endl << endl;

    cout << "********************************************" << endl;
    cout << "********  S A L E S  R E C E I P T  ********" << endl;
    cout << "********************************************" << endl;
    cout << "**                                        **" << endl;
    cout << "**                                        **" << endl;
    cout << setiosflags(ios::fixed) << setprecision(2);
    for (int count = 0; count < items; count++)
      cout << "**  Sales Item '" << names[count] << "':\t   $" << setw(9) << price[count] << "            **" << endl;
    cout << "**                                        **" << endl;
    cout << "**                                        **" << endl;
    cout << "********************************************" << endl;
    cout << "**                                        **" << endl;
    cout << "**                                        **" << endl;
    cout << "**  Total Sales:    $" << setw(9) << total << "            **" << endl;
    cout << "**  Sales Tax:      $" << setw(9) << tax << "            **" << endl;
    cout << "**                  -----------           **" << endl;
    cout << "**  Grand Total:    $" << setw(9) << g_t << "            **" << endl;
    cout << "**                                        **" << endl;
    cout << "**                                        **" << endl;
    cout << "********************************************" << endl;
		
    cout << endl << endl;

    char rerun;
    cout << "Do you want to run this program again? (y/n)";
    cin >> rerun;

    delete[] price; //delete price array because it is no longer needed.
    delete[] names; //delete names array because it is no longer needed.
			
  } while (rerun == 'y' || rerun == 'Y');

  system ("PAUSE");
  return 0;
} //End Main Function

Also note that using the (nothrow) new operator is somewhat ugly, using exceptions is preferred in general, but it's acceptable, just ugly.

Your code style and formatting makes so much more sense!!! The book I am using to learn C++ is how I normally defaulted my formatting to.

I played around with your code and produced these errors:

sales.cpp(19) : warning C4291: 'void *__cdecl operator new(unsigned int,const struct std::nothrow_t &)' : no matching operator delete found; memory will not be freed if initialization thro
ws an exception
c:\program files (x86)\microsoft visual studio\vc98\include\new(36) : see declaration of 'new'

sales.cpp(59) : error C2374: 'count' : redefinition; multiple initialization
sales.cpp(32) : see declaration of 'count'

sales.cpp(83) : error C2065: 'rerun' : undeclared identifier

I was able to figure and fix the count error on line 59 but not the others.

After I posted here, I was able to fix everything with my code and store the names with strings properly.

Here is the code:

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main()
{

char rerun;

	do //The do-while for a program rerun option
	{

	// Declare variables: counter, items, sales items, sales total, sales tax, and grand total
	int items, count;
	double * price; // creates the array to store the price
	double total = 0, percent, g_t, tax;
	string * names;

	// Input information
	cout<<"How many sales items do you have? :";
	cin>>items;
	
	// Input and storage of items names and prices
	names = new (nothrow) string[items];
	price = new (nothrow) double[items];
	if (names, price == 0)
		cout << "Error: could not allocate the names array.";
	else
	{
		for (count = 0; count < items; count++)
		{
			cout << "Enter the name of the sales item " << count + 1 << ": ";
			cin >> names[count];

			cout<<"Enter the value of the sales item " << count + 1 << ": $";
			cin>>price[count];

			total = total + price[count];
		}
	}
		
	cout << endl << endl;

	cout<<"Enter in the sales tax percentage: ";
	cin>>percent;
		
	tax = total * (percent/100);
	g_t = tax + total;
		
	cout << endl << endl;

	cout << "********************************************" << endl;
	cout << "********  S A L E S  R E C E I P T  ********" << endl;
	cout << "********************************************" << endl;
	cout << "**                                        **" << endl;
	cout << "**                                        **" << endl;
	cout << setiosflags(ios::fixed) << setprecision(2);
	for (count = 0; count < items; count++)
	cout << "**  " << names[count] << ":   $" << setw(9) << price[count] << "            **" << endl;
	cout << "**                                        **" << endl;
	cout << "**                                        **" << endl;
	cout << "********************************************" << endl;
	cout << "**                                        **" << endl;
	cout << "**                                        **" << endl;
	cout << "**  Total Sales:    $" << setw(9) << total << "            **" << endl;
	cout << "**  Sales Tax:      $" << setw(9) << tax << "            **" << endl;
	cout << "**                  -----------           **" << endl;
	cout << "**  Grand Total:    $" << setw(9) << g_t << "            **" << endl;
	cout << "**                                        **" << endl;
	cout << "**                                        **" << endl;
	cout << "********************************************" << endl;
		
	cout << endl << endl;

	cout<<"Do you want to run this program again? (y/n)";
	cin>>rerun;
		
	delete[] price; //delete price array because it is no longer needed.
	delete[] names; //delete names array because it is no longer needed.

	}

	while (rerun == 'y' || rerun == 'Y');
	
	system ("PAUSE");
	return 0;
} //End Main Function

I only have two issues with the program. I cannot figure out how to get the formatting to line up properly in the sales receipt part when it lists the names. And I receive the following warning:

salesname.cpp(29) : warning C4291: 'void *__cdecl operator new(unsigned int,const struct std::nothrow_t &)' : no matching operator delete found; memory will not be freed if initialization t
hrows an exception
c:\program files (x86)\microsoft visual studio\vc98\include\new(36) : see declaration of 'new'

I kind of fixed up the indenting and moved a little bit of the things around.

Your if statement about the allocation cannot be written that way. You have to write:

if (names == 0 || price == 0)

The way you had it with the comma is not correct. The compiler will accept the syntax but it is not correct.

The warning comes from the fact that you don't always match your new statements with a delete statement. But you do. I think your compiler is stupid (and old, 98). It is probably because of the (nothrow) new operator which is kinda weird, it is usually preferable to use the normal one, or none at all. In C++, for this kind of thing, it is much preferred to use a std::vector to store dynamic arrays, in part because it is more safe in the face of exceptions (which is the reason for the warning).

You also have an error in your code. If you fail to allocate the memory for the arrays, you only output a error message, but you do not terminate the program, meaning that there is a chance that the arrays are traversed (to print the bill) which would cause a run-time error.

The last problem, not an error but bad practice, is your obsession with declaring all the variables at the top of the program (or scope). It's generally good practice to declare variables at the place where they are first used, because it minimizes the chance of using them uninitialized and it makes the code more readable. If your book recommends otherwise, change your book, if your compiler requires that you declare variables at the start of a scope, change your compiler (it's non-standard).

With these things in mind, you get:

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;

int main()
{

  char rerun;

  do //The do-while for a program rerun option
  {
    
    // Input information
    int items = 0;
    cout<<"How many sales items do you have? :";
    cin>>items;
	
    // Input and storage of items names and prices
    vector<string> names(items); //declare a vector of strings of size "items"
    vector<double> price(items); //declare a vector of doubles of size "items"
    double total = 0.0;
    for (int count = 0; count < items; count++)
    {
      cout << "Enter the name of the sales item " << count + 1 << ": ";
      cin >> names[count];
      cout<<"Enter the value of the sales item " << count + 1 << ": $";
      cin>>price[count];

      total += price[count];
    }
  		
    cout << endl << endl;

    double percent = 0.0;
    cout<<"Enter in the sales tax percentage: ";
    cin>>percent;
		
    double tax = total * (percent/100);
    double g_t = tax + total;
		
    cout << endl << endl;

    cout << "********************************************" << endl;
    cout << "********  S A L E S  R E C E I P T  ********" << endl;
    cout << "********************************************" << endl;
    cout << "**                                        **" << endl;
    cout << "**                                        **" << endl;
    cout << setiosflags(ios::fixed) << setprecision(2);
    for (int count = 0; count < items; count++)
      cout << "**  " << names[count] << ":\t   $" << setw(9) << price[count] << "            **" << endl;
    cout << "**                                        **" << endl;
    cout << "**                                        **" << endl;
    cout << "********************************************" << endl;
    cout << "**                                        **" << endl;
    cout << "**                                        **" << endl;
    cout << "**  Total Sales:    $" << setw(9) << total << "            **" << endl;
    cout << "**  Sales Tax:      $" << setw(9) << tax << "            **" << endl;
    cout << "**                  -----------           **" << endl;
    cout << "**  Grand Total:    $" << setw(9) << g_t << "            **" << endl;
    cout << "**                                        **" << endl;
    cout << "**                                        **" << endl;
    cout << "********************************************" << endl;
		
    cout << endl << endl;

    cout << "Do you want to run this program again? (y/n)";
    cin >> rerun;
		
         
  }

  while (rerun == 'y' || rerun == 'Y');
	
  system ("PAUSE");
  return 0;
} //End Main Function

Also notice in the above that I added a "\t" in the output of the sales items, after the names are printed. This is a "tab" character, it should provide the alignment that you want with the output (at least, things will be in a straight column).

sales.cpp(51) : error C2374: 'count' : redefinition; multiple initialization
sales.cpp(24) : see declaration of 'count'

If I remove the int in line 51 it causes warnings...

sales.cpp(78) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,std::basic_string<char,std::char_traits<char>,std::alloca
tor<char> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > const *,int>' : identifier was truncated to '255' characters in the debug information
sales.cpp(78) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,std::basic_string<char,std::char_traits<char>,std::allocator<ch
ar> >,std::basic_string<char,std::char_traits<char>,std::allocator<char> > &,std::basic_string<char,std::char_traits<char>,std::allocator<char> > *,int>' : identifier was truncated to '255' characters in the debug information
c:\program files (x86)\microsoft visual studio\vc98\include\vector(47) : warning C4786: 'std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<cha
r> > > >::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information
c:\program files (x86)\microsoft visual studio\vc98\include\vector(60) : warning C4786: 'std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<cha
r> > > >::~vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >' : identifier was truncated to '255' characters in the debug information

Thank you for helping! Things are making a lot more sense!

I think that your compiler is a piece of sh**. Typically I don't recommend people use a Microsoft compiler that is older than 2008, because they are notoriously buggy, but 2008 and newer are fine.

The first error you report about the redeclaration of count is due to the fact that your compiler does not respect the standard scoping rules. In other words, the compiler is broken and non-standard.

The second batch of warnings are due to a bad implementation of the C++ standard libraries.

So, the compiler that you are using is the problem and is causing those warnings, not the code. The 1998 microsoft compiler basically pre-dates the first C++ standard (from 1998), so it is not very surprising. Get a more up-to-date compiler, either a newer version of Visual Studio (or Express edition (free)) or another IDE like CodeBlocks (with MinGW GCC compiler).

Yeah the professor has us using Microsoft Visual C++ 6.0. But I switched over to Microsoft Visual Basic 10 and going to mess around in there instead.

Tell your prof to move into the 21st century, because C++ has. Learning pre-standard C++ is a waste of time.

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.