Repeat without array

lets say i had this

int times'


cout<<"enter times you want to repeat";
cin>>times;



---->
cout<<"Hello what age are you?";
cin>>age;

<-------



how would i get it to repeat this section of codes the same amount as the user inputs?

but make it that if he input repeat by 5 times, that each time you input an age, for the 5 times, that that age is make into a variable.


example
so if you click repeat 3 times and typed in 4,6 and 8
that they would be each seprate varibles and be able to be used in further code
You can use standard containers http://www.cplusplus.com/reference/stl/ or an array of pointers to the variables you want to use.
What's wrong with arrays?
You can use for loop,while loop and do-while loop on your code but frankly if you dont use array your input in age variable will change to your last input.by the way you forgot to declare you age as int.But you can make more variable to indicate age for you not to make array if you want ^_^
Try this one and this time lets use for loop...

int times,age,ages[100];
cout<<"Enter times you want to repeat: ";
cin>>times;
for(int a=0;a<times;a++)
{
cout<<"Hello what age are you? ";
cin>>age;
ages[a] = age;
}
for(int b=0;b<times;b++)
{
cout<<"You input: "<<ages[b]<<endl;
}
Topic archived. No new replies allowed.