# Loops & variables

• 03-20-2008
SLM
Loops & variables
I'm writing a program which requires me to use a do while loop.

The specifications of the program include

1. Allow the user to enter any numbers and when the user presses zero to follow the following information..

The numbers that the user has entered (not including 0)
The average of the numbers (not including 0)
The smallest number entered (not including 0)
The largest number entered (not including 0)
The difference between the largest and the smallest number.

The problem that I am having is how do I get the variable to store more than one number???
• 03-20-2008
Dino
At a maximum,

You'll need an array of variables for the values the user entered.
You'll use another variable for the accumulator
You'll use another for the number of variables you process
You'll use another for the min
You'll use another for the max
You'll need another for the delta between the min and max.

Todd
• 03-20-2008
laserlight
Quote:

The problem that I am having is how do I get the variable to store more than one number???
Use an array, or rather, a std::vector since you need a dynamic array.
• 03-20-2008
SLM
We haven't learned std or vectors

we have learned character arrays would I be able to use that?

I do not have my written program at hand but I use a for loop as a counter so when I got the average I was able to divide it
• 03-20-2008
laserlight
Quote:

we have learned character arrays would I be able to use that?
No, you need an array of int, not char. Also, since you only know about arrays, your loop must check that the user does not enter so many numbers before entering 0 that it goes past the bounds of your array.
• 03-20-2008
Dino
Yes, of course you can use an array of chars. You'll just have to convert them to ints each time you need a value. More work, but certainly a valid approach.

Todd
• 03-20-2008
laserlight
Quote:

Yes, of course you can use an array of chars. You'll just have to convert them to ints each time you need a value. More work, but certainly a valid approach.
True, but that would limit the range of each input entered to the range of a char, and I suspect that that is an unnecessary limitation here.

EDIT:
Besides, by "array of characters" SLM is probably thinking of null terminated C-style strings.
• 03-20-2008
Dino
Well, an array of chars would indeed be limiting. An array of strings would not.

Todd