So i need to create a win32 console program that basically asks a user to input certain information about random people...ie: height, shoe size, weight. after the user has entered the information for the first person, the user is then prompted to enter the same information for another person. eventually when the user is done entering the info for all the people, the program needs to output the averages of all the inputs (average height, weight, shoe size). It would make complete sense for me if i knew exactly how many people there were total, because i could define the variables separately for each person...but how can I program this so the user has the control of how many people are entered, but my program still prints out the correct average values?
Thank you so much for the quick reply! I have a couple questions regarding your example code...
int People[Amount][Stats]; // what do the square brackets around Amount and Stats do?
switch (i) // what does switch do?
last question is what is case and what is break? I have been up to date so far on my readings for my class, so excuse my noobness since these are probably basic things that come up later in my book.
Oh sorry. int People[Amount][Stats] is a multi-dimensional array. It's basically a big box full of cubby holes where you can store data.
- http://www.cplusplus.com/doc/tutorial/arrays/
switch is basically an alternate way of writing if/elseif/else statements. It's more limiting than if statements, but is easier to read. case: x and break; are part of the switch.
- http://www.cplusplus.com/doc/tutorial/control/ (near the bottom)
EDIT:
That is the hard way.
I assumed that if he didn't know how to do this, he wouldn't know how to use vectors / classes.
I appreciate all of your help on this, but im sorry that most of it is going over my head. I have not learned vectors/classes, and I need to find out how to do this without using arrays because we haven't gotten that far in the course material.
Output to the user
Escape sequences
User input
Variables
Casting
Basic arithmetic, mod operator
Developing algorithms
Boolean values
Strings
Conditional statements
Loop statements
using what i have learned so far, i am just having trouble figuring out how store the information the user inputs for each person and recalling it later in the program whenever the user decides to stop entering more people.
that makes a lot more sense to me now! could i put "do" loops inside the "for" loop? one other thing is i have to reprompt the user to enter valid information if they don't for each variable. I already have my do loops written for that case, but would i simply put them in the for loop?
You can put loops within loops yeah, that's called nesting. You can't really protect against much in the early stages, but you can do something like "if Height > 500 || Height < 1".
is there a way to code this so that the user doesn't say at the beginning how many people they are entering? my program is pretty specific, and it says that the user inputs the Height, weight, and shoe size for the first person...and is only then prompted "do you want to enter another student?" if yes, the program asks for the same inputs from the user for the 2nd person and so on and on. once the user selects not to enter another student, the program prints out the maximums and averages for all the people entered. Maybe i should have been more clear on that earlier...i just want to make sure im piecing it all together correctly.