Tuesday, July 28, 2009

How do you input numbers into an array and then display the average with C++ using Quincy2005??

What I have to do is ask the user to input a set of numbers. Those numbers have to go into an array. Then calculate the average so the output will display each number and whether it is above or below the average.





I'm supposed to use a loop.. I'm guessing for loop?? I'm not sure. But the main problem is how to get the user to input the numbers into the arrays???





The program I am using to build this is Quincy2005 and I'm going by C++





Thanks for the help!!

How do you input numbers into an array and then display the average with C++ using Quincy2005??
for(int i=0;i%26lt;size_of_array;i++)


{


cin%26gt;%26gt;array_name[i];


}





this is to take input from user


next you want to take average


so declare a variable of type int %26amp; initialize to 0


again start a for loop


for(i=0;i%26lt;Array_size;i++)


{


sum=sum+array_name[i]; here you add the number to sum(integer type variable)every time the program execute this line the sum will increment with the number stored in array


}


now sum contains all the numbers addition result


average= sum/array_size


for average you will divide the sum of all numbers in array by the no of elements in array
Reply:scanf() ?

narcissus

No comments:

Post a Comment