[C++] How to ignore inputs after n number of required inputs? via /r/learnprogramming


[C++] How to ignore inputs after n number of required inputs?

I have a code where it automatically fills in n number of observations for an integer vector using for loop. Here, the n is set to 4 so any number of inputs greater than 4 needs to be ignored – this is because instead of typing each input per line in console, I made it so that the user only needs to type a single line of n(s). For example, if the user wants to put 0,1,0,1 then he only needs to type 0 1 0 1 in the console.

The problem is that I want to implement additional codes that ignores user's input should he write number of observations that are greater than 4. Hence, 0 1 0 1 0. Currently, it seems that if I do this, the four numbers register as it should and it automatically skips to the part where the next cin is called.

How can I discard the fifth, or any inputs greater than n?

Thanks.

Submitted July 17, 2017 at 06:49AM by VonLuftwaffle
via reddit http://ift.tt/2uqD444

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s