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
#include <iostream>
usingnamespace 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();
}
elseif (day >= 32, day <= 59)
{
cout << "February!";
cin.get();
}
else
cout<<"Thanks";
cin.get();
return 0;
}
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>
usingnamespace 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!";
elseif (day >= 32 && day <= 59)
cout << "February!";
return 0;
}