# Thread: Three ONE dimensional arrays

1. ## Three ONE dimensional arrays

Hi
What I need to do is declare three one dimensional arrays neamed price, quantity and amount. Each array shoule be capable of holding 10 elements. Using a for loop input values for the price and quantity arrays. The entries in the amount array should be the product of the corresponding values in the price and quantity arrays. After all of the data has been entered it should display the following output.
Quantity Price Amount
______ ____ ______
I know my program is a bit of a mess and not with out structure problems because I get a thought in my head and just type it out before I forget but if I could at least get help with the part of making the array print out correctly I would appericate it. Please help!

Code:
```#include <stdio.h>
int main()

{
#define Bulk 10
#define How_Much 10
#define Sticker_Shock 10
int Quantity[Bulk];
int Price[How_Much];

int i;
float Amount[Sticker_Shock];

for (i = 0; i < Bulk; i++)
{
printf("Quantity");
scanf("%d", &Quantity);

}

for (i = 0; i < Bulk; i++)
printf("Quantity %d = %d\n", i, Quantity[i]);

for (i = 0; i < How_Much; i++)
{
printf("Price: ");
scanf("%d", &Price[i]);
}

for (i = 0; i < How_Much; i++)
printf("Price %d = %d\n", i, Price[i]);
}

Amount=Quantity * Price;
}
for (i = 0; i <= 9; i++)

printf("%3d %7d %6d\n", Amount,Quantity,Price);

getchar();
getchar();
return 0;
}```

2. The name of an array is not a variable and can't be used as an lvalue.

3. Could you please explain what you mean by lvalue? All I want to know is how to make this one dimensional array print out so it prints out Quantity Price and Amount with line underneath them.

Code:
`Amount=Quantity * Price;`
You need to use a loop if you are trying to access each element. You cannot mutliply or assign arrays.

An lvalue is something that can go on the left side of assignment. Arrays cannot.

5. Any particular reason You quoted yourself in your initial post? An attempt at third person narrative?

You got your first three loops fine, using arrays correctly etc, by the time we get down to the fifth loop it's all done horribly wrong. Why did 9 suddenly become important when you have nicely name constants like Sticker_Shock? (Note that you shouldn't have 3 separate constants, they can all use the same one)
Why do you have non-matching braces?

Here's a big hint: When you know that your program is a bit of a mess, tidy it up as best you can before posting! We don't want to wade through the mess of bugs that would be obvious to yourself if you cleaned the code up first, and you don't want the embarrasment of that either.

6. Hi iMalc

I got a little confused about this array program. I know that I have the first few loop correct but after that I'm not sure what to do. I do this all the time I'm able to figure out most of the program then I totally go blank my teacher told me I'm to up tight and I need a beer. I will work on it today and post what I have later. Thank you so much for the information.