Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
1.33/5 (3 votes)
See more:
How to create an array of size 7 which stores product price for a week and calculate average price?
Posted
Comments
Dean Oliver 19-Mar-12 15:47pm    
should have learnt the basics of c# first.

C#
double [] prices = new double[7];


There is a very neat site to find answers to these questions: Here[^]
 
Share this answer
 
v2
Comments
Shahin Khorshidnia 19-Mar-12 10:44am    
No. That array stores exactly 7 values.
V. 19-Mar-12 10:46am    
Excuse me? Array size will be 7 index will go from 0 - 6.
Rajesh Anuhya 19-Mar-12 10:48am    
Agreed!
--RA
Wayne Gaylard 19-Mar-12 10:52am    
Oops - my bad! Don't know what I was thinking of.
V. 19-Mar-12 10:55am    
Don't worry, similar things happen to me :-)
Here is good link for you,
this may help you.
http://java2s.com/Code/CSharp/Collections-Data-Structure/Declareallkindsofarrays.htm[^]

Thanks
--RA
 
Share this answer
 
Comments
Member 8714846 19-Mar-12 10:42am    
Thanks...
Rajesh Anuhya 19-Mar-12 10:43am    
Vote answers,if it's helps you.
--RA
ProEnggSoft 19-Mar-12 10:57am    
Good link to array declarations. 5!
To calculate average price:
C#
void Main()
{
    decimal[] ProductPrice ={10,20,30,40,50,60,70};

[edit]Average method can be used[/edit]
    //    decimal avgPrice = ProductPrice.Sum() / ProductPrice.Length;
    avgPrice = ProductPrice.Average();
    Console.WriteLine ("The average of prices = {0}",avgPrice);
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900