Im having trouble determining what loop to use and how to use it. I have to be able to have a user enter multiple names and ages and the program must tell who is the oldest. I know the code below is incomplete it is just a starting point, is what i have at the moment.
it seems like you are at the very beginning of programming, you should check out some beginner tutorials first, as example you can not store names (as strings or chars) in an int variable.
B2T:
I think it would be the simplest method to use while, check if the entered age is greater than the highest one recorded, if yes, replace. if not, get next age. There are multiple solutions to your problem, I wrote this as an example.
for and while overlap, because a while loop is just a for loop without all the parts.
while(something);
is the same as
for(;something;);
but the second statement is odd and it is preferred that you just use a while if you have no preconditions or control updates.
for is preferred over
x = 0;
while (x < 10)
x++;
better to just have this, to handle the loop control all together
for(x = 0; x < 10; x++)
and do-while is to handle loops that you want to execute once no matter what, and more times conditionally. This is usually defined by user input (where user may be a device, or service, or something beyond a human at the keyboard)
do
cin >> x; //you always want to read x once, at least!
other stuff;
while(x != quit)
I think you want the do-while above. But the key to choosing which to use is really how it looks. You can make it work either way in many cases, as seen above, but there are natural fits to your code that make a for or a while the better choice. Do-while also has overlap, but it is usually easier to see when you need it compared to the others.
Ah i see what my problem was. Thank you both for helping me, now i actually know how to use the loops. Also in order to use a string as a variable do you have to do #include <string>