Input: Month name (January / February / … / December)
Output: Season (Winter / Spring / Summer / Autumn)
Winter: Dec – Feb
Spring: Mar – May
Summer: Jun – Aug
Autumn: Sept – Nov
I have tried:
Program Months;
var
Month:String;
begin
writeln('Insert month name:');
readln(Month);
if Month = 'March' or Month = 'April' or Month = 'May' then
begin
writeln(Month,' is Spring month');
end
...
etc
...
end.
But this program is not working.
Operator precedence – it’s important. You need to write:
This is because in Pascal,
orhas a higher priority than=so what is actually being evaluated is:Which is obviously meaningless and will not compile (I might’ve made a mistake on the line above but it’s the general idea). Please refer to this link to learn more about operator precedence in Pascal.