How to do a loop how many times want the user

How to do a loop from a cin number? Thanks in advance!
I use Code::Blocks 16.02

1
2
3
4
5
6
7
8
//Example

int n;
cin >> n; //Entering 7
loop(7 times)
{
//code
}
closed account (E0p9LyTq)
How would you hard-code create a loop that loops 7 times? Just replace the 7 with your variable n.
1
2
3
4
5
6
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
//code
}
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <string>

int main()
{
  int loop_limit;
  std::cin >> loop_limit;
  
  for (int i = 0; i < loop_limit; i++)
    std::cout << "Try doing it yourself Cosmin!\n";
}
+Chipp93
+Kemort

Sorry, i fixed the problem, i just forget how to do it, i was confused, i wanted to close this thread but i forget! Sorry!

Thanks anyways.
Topic archived. No new replies allowed.