Sep 8, 2012 at 2:54am UTC
Hello everyone. Can anyone help me with this problem using while or for or do loop?
The desired output should be like this:
_____________________________________
Enter a number : 5 //for example
1, 2, 3, 4, 5
Try again? Y/N
_____________________________________
I've tried various code loop code but I can't really make it. Thanks for any help.
Sep 8, 2012 at 3:08am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
int main(void ) {
int amount;
char cont = 'y' ;
while (cont == 'y' ) {
std::cout << "Enter a number: " ;
std::cin >> amount;
for (int i = 1; i <= amount; ++i)
std::cout << i << ' ' ;
std::cout << "\nContinue? <y/n>: " ;
std::cin >> cont;
}
return 0;
}
Is this what you are looking for?
Last edited on Sep 8, 2012 at 3:13am UTC
Sep 8, 2012 at 3:17am UTC
Thank you. I'll try it then I'll say if it is. Thank you again.
Sep 8, 2012 at 3:23am UTC
Oh, I have another problem, since I not yet familiar with loop codes, would you be so kind so make a simple flow chart of this. Thank you.
Sep 8, 2012 at 3:39am UTC
What exactly would you want it to look like? Just write up a quick example while I go take a shower.