Hi ;
I know how to solve the same problem if i have limit numbers ,but here i have n intergers .How can the compiler understanst me when i need n integers ,like this question:

Write a program that takes an n number of integers and calculates their average.
Using for or while loop!

Recommended Answers

All 3 Replies

you should create a loop which takes in a number with every pass, adds it to a total number and stores how many numbers where entered (how many passes the loop made)

Then you would need something to break out of the loop.

When you're out of the loop, calculate the average value and display it.

This is not a very difficult assignment if you understand how loops work.

Good luck!

cin >> n;

That will allow the user to input a number, if that's what you were looking for. If you need to know how to use loops, you should do a bit more studying. It isn't very hard, I promise!

I know that it is not hard ,but it needs practice .
Thanks for your reply.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.