Problem with having to input twice

I am writing a simple program that will take a number (range 1-366) and output the month that that number is contained in. I am pretty much finished, but am having the issue where you have to put in the input TWICE for it to give an output.
For instance, i type in "32", and nothing happens. When I type in "32" again, then the desired output shows.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifndef INTRANGE_H
#define INTRANGE_H

class IntRange
{
	private:
		int input;
		int lowest;
		int highest;
	public:
		IntRange (int, int);
		int getInt();
		
};

#endif 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include "IntRange.h"
using namespace std;

int main()
{
	IntRange input (1, 367);   // keeps numbers in yearly range
	char a=0;
	int day;                     // holds user input day
	cout<<"This program converts days entered to the month of the year.\n";
	cout<< "Please enter a day of the year. Keep in mind that this year is a LEAP YEAR.\n";
	cout<< "To exit, enter 'exit'\n";
	

	day=input.getInt();
	
	while (a==0)
	{
		
		 if (day >= 1 && day <= 31)
			cout << "This day falls into the month of January.\n";
		 if (day >= 32 && day <= 60)
			cout << "This day falls into the month of February.\n";

		day= input.getInt();
		
	}
	return 0;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// input.cpp : Allows user to input one day of the year,
// and blocks anything out of that range
#include "IntRange.h"
#include <iostream>

using namespace std;

IntRange::IntRange(int=1, int=366)
{
	lowest= 1;  // lowest number allowed in the year range
	highest= 366;  // highest number in a year range

}
int IntRange::getInt()
{
	
	cin>>input;

	if(!( cin>>input))
	{
		cin.clear();
		cin.ignore(numeric_limits<streamsize>::max(), '\n');
		cout<<"Invalid input. Try again.\n";
		cin>>input;
		cin.ignore();
	}

	while (input < lowest || input > highest) //loop to ensure the number entered is within range
{
	cout<< "That is not a number of the year.\n";
	cout<< "Enter a value from " << lowest;
	cout<<" to " << highest <<".\n";
	cin.ignore(numeric_limits<int>::max(), '\n');
	cin>>input;
	cin.ignore();
	
}
	

	
	return input;
}


Any help, please?
The reason is that you ask twice: on line 17 and 19
The reason is that you ask twice: on line 17 and 19


Good spot!! I missed that one.
Thanks you guys, I was unaware of how to use that correctly.
Topic archived. No new replies allowed.