How to print the season name of the year based on the month number in C++

1 Answer

0 votes
#include <iostream>

void printSeason(int month) {
    switch (month) {
        case 12: case 1: case 2:
            std::cout << "Winter" << std::endl;
            break;
        case 3: case 4: case 5:
            std::cout << "Spring" << std::endl;
            break;
        case 6: case 7: case 8:
            std::cout << "Summer" << std::endl;
            break;
        case 9: case 10: case 11:
            std::cout << "Autumn" << std::endl;
            break;
        default:
            std::cout << "Invalid month number!" << std::endl;
    }
}

int main() {
    int month = 9;
    
    printSeason(month);
}



/*
run:

Autumn

*/

 



answered Sep 9, 2025 by avibootz
...