fred rosenberger wrote:there is nothing fancy about it...it would just be a variable you create. just like you have your "double average = 0", you would set up a "int numInputs = 0".
Then each time you get a new value input, you add 1 to it. there are several ways of doing that:
numInputs = numInputs + 1;
numInputs += 1;
in fact, adding 1 to an int is so common, there is a special shortcut:
fred rosenberger wrote:
Darrin Altman wrote:I would count how many numbers you read off and then divide by that number. Contemplating this I am trying to think of a method to figure out how many numbers the user input but am at a loss. I am going to go back and read the chapter again and see if I can figure this out.
So how do you count how many numbers are added? each time you hear a new value from me, you increase your count by 1.
So you need to keep track of two things...the running total of all the input numbers, and a count of how many numbers you've gotten.
fred rosenberger wrote:the first thing you should always do is work out how you'd do something by hand - i.e. using paper and pencil.
so, assume I was going to read a list of numbers, and I want you to tell me the average of them once I tell you i'm done. How would you do that?
Wouter Oet wrote:sumOfNumbers / numberOfNumbers = average
shuba gopal wrote:Hi Darrin,
Looks like switch-case will be useful for you.
Have a look at this sample program.http://www.cafeaulait.org/course/week2/42.html
If you are printing upto n, for(int b =0;b<n;b++). Use the switch case inside this for loop