Monday

May 25, 2015

May 25, 2015

Posted by **nethiyaa** on Tuesday, May 10, 2011 at 2:27am.

- c++ -
**MathMate**, Tuesday, May 10, 2011 at 7:13amSince one of the requirements is to find out how many are above average, and there are only 10 numbers, it would be a good idea to store the numbers in an array so you would not have to read the numbers a second time.

Reading it more than once is not a good idea because we never know if the file has changed in the mean time.

You also have to know if the numbers are integers (int), or are they real numbers (double or float).

Eventually, the average will have to be a double or float using type cast.

Here's a possible pseudocode. Work on the coding, and post if you have further questions.

// start

Declare array of 10 numbers, num.

Declare variable sum, initialize to zero.

Declare numVar, initialize to 10.

Declare mean, initialize to zero.

Declare count, initialize to zero.

Read input numbers into array num.

// calculations

for i=0 to numVar-1

{

sum ← sum + num[i]

}

mean ← ((double)sum)/numVar

count=0

for i=0 to numVar-1

{

if num[i]>mean then

{

count ← count + 1

}

}

// output

Print numVar, mean, count