Beginner Program

Needing help with a beginner program here. First class I've had on C++ and I'm having some trouble with some if statements and else if statements. If someone can just supply me with a starting point I think I can pretty much figure the rest out. Problem: User inputs a value of 1-365 and a program outputs which month that day will fall in. Ex input day 28 output January. Thanks
Everything you'll need you'll find here: http://www.cplusplus.com/doc/tutorial/control/
I've looked thru that a good bit and I'm still having problems when I'm going to build. Does this look anything near what it needs to be?

#include <iostream>

using namespace std;

int main ()
{
int day;

cout << "Enter a day in the range of 1-365, for ex 248."
<< endl;
cin >> day ;

if (day <= 31)
cout << "January!";
else if (day >= 32, day <= 59)
cout << "February!";

return 0;
}
i think you forgot to put a cin.get() in your statement.

And when you are putting an "if else statement", do not forget to put an else on it.. By the way, here is the code.

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
#include <iostream>

using namespace std;

int main ()
{
int day;

cout << "Enter a day in the range of 1-365, for ex 248."
<< endl;
cin >> day ;

if (day <= 31)
{
   cout << "January!";
   cin.get();

}
else if (day >= 32, day <= 59)
{
   cout << "February!";
   cin.get();

}
else

    cout<<"Thanks";
    cin.get();



return 0;
}



Best regards,
nemesis
Last edited on
Thanks man! that fixed it!
What is this supposed to do?

 
else if (day >= 32, day <= 59)


your , is probably supposed to be a &&(logical and). i like your use of exclamation points!


i had no idea we could put a series of non-declarative stuff inside and if():
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;

int main() {
	int day;

	if (cout << "Enter a day in the range of 1-365, for ex 248." << endl, cin >> day, day <= 31)
		cout << "January!";
	else if (day >= 32 && day <= 59)
		cout << "February!";
	
	return 0;
}

how new school!
Topic archived. No new replies allowed.