Click here to Skip to main content
15,920,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone,

I have a problem. How do you declare number of cin's. If you know what I mean.

Eg.

User Input: 5

5 cin's (user has to input 5 numbers)

User Input: 20 12 13 14 15


User Input: 7

7 cin's (user has to input 7 numbers)

User Input: 3 4 5 6 7 8 9

What I have tried:

--------------------------------------------------------------------------------------
Posted
Updated 30-Dec-18 13:50pm

1 solution

Have you got to loops yet? A for loop would work well to do this. Here is a for loop :
for( int n = 0; n < inputCount; ++n )
{
   // do something inputCount times here
}
If you want to input some numbers what are you going to do with them? I am going to guess you want to save them. You need a place to save them so this will allocate some:
int * inputs = new int[inputCount];
You can combine these two operations, prompt for entry, and save the input like this :
int * inputs = new int[inputCount];
for( int n = 0; n < inputCount; ++n )
{
    cout << "enter input " << n+1 << " : ";
    inputs[n] << cin;
}

// do something else with the input here

delete [] inputs;   // release allocated memory
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900