1. 2d arrays

how to print a specific number in the array? Like for my program I have to calculate the cost of 5 companies in 4 years. For the last function how do I let say print the total cost of company 1.

Code:
```#include <stdio.h>
void getvalues();
double totalcost(float);
void main()
{

getvalues();
y=double totalcost(cost);

}

void getvalues()
{
float cost[5][6];
int i,y,com=0,year=0;
for(i=0;i<5;i++)
{
for(y=0;y<4;y++)
{
com=i+1;
year=y+1;
printf("Please enter the electricity cost for Company %d, year %d:",com,year);
scanf("%f",&cost[i][y]);
}
}
}
double totalcost(float c)
{
int selection;
printf("Please enter the number of company");
scanf("%d",selection);```

2. You need to figure out who "owns" your data. Currently the getvalues function owns your cost data, which means that it is fruitless for any other function (like main, or totalcost) to even attempt to dream about the data, let alone use it in a meaningful way.

It is typical for your data to be "owned" by the main program, which passes it to functions as necessary for them to operate on. So you should put your array in main, pass it to getvalues to be filled in, and then pass it to totalcost to be calculated with.

3. Use variables that make sense, and you will have your answer:
Code:
```float costs[ 5 ][ 6 ];
int cost, company;

printf( "Which company (0-4)?\n" );
scanf( "%d", &company )
if( company > -1 && company < COMPANIES )
for( cost = 0; cost < COSTS; cost++ )
dosomething( costs[ company ][ cost ] );```
Now it doesn't actually matter if you treat "rows" as the company, or the "columns" as the company. You can do whatever you want. Just stick with whatever you choose throughout your program and don't flip-flop back and forth.

Quzah.