Using if Else

Can Someone help me pls :( i need this kind of output
[1]Seasons of the year

Input a number: 2

February is WINTER

Happy Valentine’s Day

Input a number: 3

March is SPRING

Congratulations, Graduates!


This is what i need to input
1 January WINTER

2 February WINTER

3 March SPRING

4 April SPRING

5 May SPRING

6 June SUMMER

7 July SUMMER

8 August SUMMER

9 September FALL

10 October FALL

11 November FALL

12 December WINTER

Use if-else
This is my code so far
#include<iostream>
using namespace std;

int main()
{

int x;
cout<<"Input a number"<<endl;
cin>>x;


{if (x==1)

cout<<"January is Winter"<<endl;
cout<<"HAPPY NEW YEAR"<<endl;
}else if (x==2){
cout<<"Febuary is WINTER"<<endl;
cout<<"Happy Valentine's Day"<<endl;
}else if (x==3){
cout<<"March is SPRING"<<endl;
cout<<"Congratulations, Graduates!"<<endl;
}else if (x==4){
cout<<"April is SPRING"<<endl;
}else if (x==5){
cout<<"May is SPRING"<<endl;
}else if (x==6){
cout<<"June is SUMMER"<<endl;
}else if (x==7){
cout<<"July is SUMMER"<<endl;
}else if (x==8){
cout<<"August is SUMMER"<<endl;
}else if (x==9){
cout<<"September is FALL"<<endl;
}else if (x==10){
cout<<"October is FALL"<<endl;
}else if (x==11){
cout<<"November is FALL"<<endl;
}else if (x==12){
cout<<"December is WINTER"<<endl;
}
system("PAUSE");
return 0;

}
For GOD sake's please indent! Makes the code more readable.
Here is what you were probably looking for.

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<iostream>
using namespace std;

int main()
{

int x;
cout<<"Input a number"<<endl;
cin>>x;

while(x < 1 || x > 12){
        cout << "Enter 1-12: ";
        cin >> x;
    }

if(x == 1){
    cout<<"January is Winter"<<endl;
    cout<<"HAPPY NEW YEAR"<<endl;
}
else if(x == 2){
    cout<<"Febuary is WINTER"<<endl;
    cout<<"Happy Valentine's Day"<<endl;
}
else if(x == 3){
    cout<<"March is SPRING"<<endl;
    cout<<"Congratulations, Graduates!"<<endl;
}
else if(x == 4){
    cout<<"April is SPRING"<<endl;
}
else if(x == 5){
    cout<<"May is SPRING"<<endl;
}
else if(x == 6){
    cout<<"June is SUMMER"<<endl;
}
else if(x == 7){
    cout<<"July is SUMMER"<<endl;
}
else if(x == 8){
    cout<<"August is SUMMER"<<endl;
}
else if(x == 9){
    cout<<"September is FALL"<<endl;
}
else if(x == 10){
    cout<<"October is FALL"<<endl;
}
else if(x == 11){
    cout<<"November is FALL"<<endl;
}
else if(x == 12){
    cout<<"December is WINTER"<<endl;
}

return 0;
}
Last edited on
closed account (48T7M4Gy)
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
#include<iostream>
#include <string>

using namespace std;

int main()
{

int monthNo = 0;

string month[] = {
    "Jan","Feb","Mar","Apr",
    "May","Jun","Jul","Aug",
    "Sep","Oct","Nov","Dec"
    };

string season[] = {
    "Winter", "Winter",// blah, blah};
    
string greeting[] = {
    "Happy New Year",// blah bla};    
    
cout<<"Input a number"<<endl;
cin >> monthNo;

cout << greeting[monthNo] << "for the" << season[monthNo] <<  " of " << month(monthNo) << endl;

return 0;

}
Thankyou :)
you put a { in front of your if statement and it needs to be after.
Topic archived. No new replies allowed.