Variable question (Do not really know how to call this problem)

For example, into "cin" I enter number 2. And then it shows me this

Opinion 1
Opinion 2

When I enter 4 it gives me 4 readings

Opinion 1
Opinion 2
Opinion 3
Opinion 4

It should give you as many options, as you enter in variable.

I try to do this like that, but I think its not the best solution
1
2
3
4
5
6
7
8
9
10
11
12
  if(a==2)
{
cout << "Opinion 1" << endl ;
cout << "Opinion 2" << endl ;
}
if(a==3)
{
cout << "Opinion 1" << endl ;
cout << "Opinion 2" << endl ;
cout << "Opinion 3" << endl ;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>

int main()
{
    unsigned numOpinions;
    std::cout << "How many opinions?: ";
    std::cin >> numOpinions;

    for(unsigned i = 1; i <= numOpinions; ++i)
    {
        std::cout << "Opinion " << i << std::endl;
    }
}
Last edited on
Topic archived. No new replies allowed.