Getting extra cin line before while and if

This is a very odd problem that I just can't seem to figure out! I am getting a cin line twice when I should only get one. Can anyone help with this? I don't even know how to google this problem, to be honest.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<iostream>

using namespace std;

int main()
{
        //assign variables
        int number;

        //user defined variables
        cout << "Input the number: ";
        cin >> number;
        if (!(cin >> number))
        {
                cin.clear();
                cout << "Invalid Input! Input the month (numerically): ";
                cin.ignore( 100 , '\n' );
        }
        cout << number << endl;
        return(0);
}


This is a working piece of the code with an output for verification. Weird thing is, it takes the second input as the cin. Where is the first input coming from?

Thanks in advance,
Arcie
You use the istream object cin on both line 12 and 13. Advice, remove the one on line 12. Also there are no while statements in your code, just if-statement
The reason I mentioned while is because if I switch while in for if, I get the exact same issue. I appreciate your response! I didn't realize that having the cin in the if statement would actually call for an input! Noob mistakes!

Thank you so much!
Arcie

PS, I like this forum! You all rock!!!
Topic archived. No new replies allowed.