I have started this program and it builds fine but when I debug it
I get a run-time check error #3, the variable total_sales is being
used without being defined. Can some one help me out with this?

#include <iostream>

using namespace std;

void main()

{

int sp[10][7] = {89, 92, 87, 85, 95, 81, 90, 

78, 81, 87, 77, 80, 88, 84,

88, 89, 91, 84, 97, 80, 88,

61, 62, 73, 75, 55, 73, 69, 

95,100, 99,100, 95, 97, 98 };

int choice,sales_anyd,tot_store_sales,sp_number,

sales_person,total_sales,sp_num,avg,s;


cout << "1 - Average sales for a salesperson ";

cout << "2 - Total sales for any day ";

cout << "3 - Total sales by store for the week ";

cout << "4 - Print the sales by salesperson ";

cout << "0 - Exit ";

cout << "Enter your choice: ";

cin >> choice;




{

switch (choice)

{

case (1): 

cout << "Enter a sales person number :";

cin >> sp_num;

cout << "Enter a total sales any day :";

cin >> sales_anyd;

for (s = 0; s <= 9; s++)

{

total_sales = sales_anyd * total_sales[sp][s];

}

cout << "sales person total sales " << total_sales << " for "

<< "sales person " << sales_person << endl;

break;


}


}

}

What is it defined as?
Where/how is it used?
Does the use and the definition match?

And please format your code. If it gets any longer and more complex, we won;t be able to follow it. If you want more help, you do want us to be able to read it, right?

I am trying to get it to do the math so I can get an average for the sales person. Sorry about the code in my first post

#include <iostream>
using namespace std;
void main()
{
	int sp[10][7] = {89, 92, 87, 85, 95, 81, 90, 
		          78, 81, 87, 77, 80, 88, 84,
		          88, 89, 91, 84, 97, 80, 88,
		           61, 62, 73, 75, 55, 73, 69,	
		         95,100, 99,100, 95, 97, 98 };

int choice,sales_anyd,tot_store_sales,sp_number,
sales_person,total_sales,sp_num,sp_sales,avg,s;

	
	cout << "1 - Average sales for a salesperson ";
	cout << "2 - Total sales for any day ";
	cout << "3 - Total sales by store for the week ";
	cout << "4 - Print the sales by salesperson ";
	cout << "0 - Exit ";
	cout << "Enter your choice: ";
	cin >> choice;


	
	{
	switch (choice)
		{
		case (1):					
		cout << "Enter a sales person number :";
			cin >> sp_num;
		cout << "Enter a total sales any day :";
			cin >> sales_anyd;
			for (s = 0; s <= 9; s++)
			{
			avg = sp_sales * total_sales[sp][s];
			}
                                               cout << "average sales " << avg << endl;

		

		}
				
	}
}

Edited 6 Years Ago by WaltP: C'mon, CODE Tags. 16 posts and you haven't read the Member Rules yet?

I don't see where you even read my post, let alone tried to answer my questions.

I am trying to get the code to perform #1 in the menu, and I am using total_sales as part of the math equation and I think that is where i am getting the error but Im not sure why

This article has been dead for over six months. Start a new discussion instead.