1. ## automobile program

This is a program i am trying to get working. It is supposed to read in values of cars and then input howmany sold for each model for each sales person. it works fine until it gets to ten then it goes 1232323 and will not stop can anyone help me or show me as to why this is happening?
Code:
```#include <iostream>
using namespace std;

void main()
{
int i,j;
int iAuto[10];
int iSales[9][11];
int iTotSalesperPerson[11];
int TotSales;

// Reading prices for the Automobiles
for(i=0;i<10;i++)
{
cout << "Automobile "<< i << " Price: ";
cin >> iAuto[i];
}
// Reading Sales for Models & Sales Person
for(i=1;i<=10;i++)
for(j=1;j<=8; j++){

cout << "Model "<< i << " - Sales Person " << j << ":";
cin >> iSales[i][j];

}
// Sales Calculation for each person
for(j=1;j<=8;j++)
for(i=1;i<=10;i++){
iTotSalesperPerson[j]+=iSales[i][j];
cout << iTotSalesperPerson[j];
}

// Total Sales
for(j=1;j<=8;j++){
TotSales+=iTotSalesperPerson[j];
cout << TotSales;
}
}```

2. arrays are zero based
so use i=0;i<10;i++ loops

2. in your case iSales[i][j] i goes to 10 and j to 8 - so switch dimentions in declaration of the array

3. main should be int

4. probably use of vectors is preffered over the arrays

3. cool it let me add all the cars however it says the use of
Code:
`TotSales`
is used without being defined after i enter all the cars any ideas?

4. TotSales+=iTotSalesperPerson[j]; is evaluated to
TotSales=TotSales+iTotSalesperPerson[j];
because you do not initialize the TotSales to anything it contains garbage

So what you get is
TotSales="garbage"+iTotSalesperPerson[j];

5. here is the code
Code:
```#include <iostream>
using namespace std;

int main()
{
int i,j;
int iAuto[10];
int iSales[9][11];
int iTotSalesperPerson[11];
int TotSales = 0;

// Reading prices for the Automobiles
for(i=0;i<10;i++)
{
cout << "Automobile "<< i << " Price: ";
cin >> iAuto[i];
}
// Reading Sales for Models & Sales Person
for(i=0;i<=10;i++)
for(j=0;j<=8;j++)
{
cout << "Model "<< i << " - Sales Person " << j << ":";
cin >> iSales[j][i];
}
// Sales Calculation for each person
for(j=0;j<=8;j++)
for(i=0;i<=10;i++)
iTotSalesperPerson[j]+=iSales[j][i];
cout << iTotSalesperPerson[j];

// Total Sales
for(j=0;j<=8;j++)
TotSales += iTotSalesperPerson[j];
cout << TotSales;

}```
now it only displays one value filled with garbage i dont understand

6. Code:
`    int iTotSalesperPerson[11] = {0}; //this initializes all your array elements.`

7. thanks for that info it displays now the total number of automobiles sold for all employees, i need it to display prices and the sales table and calculate the total dollar sales for each salesperson and the total dollar sales for all salespersons how would i start that?

8. use loops. try it first and then come back when you have problems.

http://www.cprogramming.com/tutorial/lesson8.html

9. Note that
Code:
```// Sales Calculation for each person
for(j=0;j<=8;j++)
for(i=0;i<=10;i++)
iTotSalesperPerson[j]+=iSales[j][i];
cout << iTotSalesperPerson[j];```
means
Code:
```for(j=0;j<=8;j++)
{
for(i=0;i<=10;i++)
{
iTotSalesperPerson[j]+=iSales[j][i];
}
}
cout << iTotSalesperPerson[j];```

10. thanks gents i read the loop but i dont understand how to make it work! can someone show me?

11. What do you want repeated? How many times? Is the number of the repetition it's on important at a given time?

Are your loops going to count, or are they going to wait for something (other than counting)?

12. When you first start, put braces around all your control statements so that you will know what's being repeated. Also, be careful that you don't use array indexes that are too big or small, as people have stated. For instance:
Code:
```for(j=0;j<=8;j++)
for(i=0;i<=10;i++)```
These will use the eighth and tenth items respectively, whereas, a ten item array only has indexes up to nine, and so forth.

13. Originally Posted by citizen
Code:
```for(j=0;j<=8;j++)
for(i=0;i<=10;i++)```
These will use the eighth and tenth items respectively, whereas, a ten item array only has indexes up to nine, and so forth.
j is 0-8 inclusive, and i is 0-10 inclusive, therefore they are the ninth and eleventh items.

gunghomiller: the convention is to use the < operator though (for readablility)
Code:
```for(j=0; j<9; j++)
for(i=0; i<11; i++)```
if you don't know what to write in code, then write out step by step in english what you want the program to do. try to make it resemble code as much as possible.

14. > j is 0-8 inclusive, and i is 0-10 inclusive, therefore they are the ninth and eleventh items.
That is assuming that I didn't count from the zeroth element, of course.