Answer to Question #336352 in C++ for Secret Agent

Question #336352

Dealing With Months

by CodeChum Admin

We're done dealing with days. It's time to step up and now deal with months!


Instructions:

  1. In the code editor, you are provided with a code in the main() which has 12 cout's. Each cout prints a month with its corresponding value. For this program, January is 1, February is 2, March is 3, and so on. When you run the initial code, you will encounter errors because these month names that have been printed don't exist yet.
  2. Your task is to create an enum data type which contains these month names as values so that when we run the code, there will be no more error.
  3. Do not edit anything in the main().

Output


January·=·1
February·=·2
March·=·3
April·=·4
May·=·5
June·=·6
July·=·7
August·=·8
September·=·9
October·=·10
November·=·11
December·=·12
1
Expert's answer
2022-05-02T13:37:44-0400
#include <bits/stdc++.h>
using namespace std;


enum month { 
	January = 1, 
	February, 
	March, 
	April, 
	May, 
	June, 
    July, 
	August, 
	September, 
	October, 
	November, 
	December 
	};


int main()
{
    cout << January << endl;
	cout << February << endl;
	cout << March << endl;
	cout << April << endl;
	cout << May << endl;
	cout << June << endl;
    cout << July << endl;
	cout << August << endl;
	cout << September << endl;
	cout << October << endl;
	cout << November << endl;
	cout << December << endl;
	
	/*or just
    
    for (int i = January; i <= December; i++)
        cout << i << " ";
 */
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS