
Patrick B. answered 05/24/21
Math and computer tutor/teacher
typedef enum _TDirection
{
EAST=0,
NORTH=90,
WEST=180,
SOUTH=270
} TDirection;
Kat H.
asked 05/24/21Define a enumerated type Direction to make the following code work correctly. It should associate EAST with the value 0, NORTH with the value 90, WEST with 180 and SOUTH with 270.
Code:
#include <iostream>
using namespace std;
//Do not modify anything on or above the line below this
//YOUR_CODE_BELOW
//YOUR_CODE
//YOUR_CODE_ABOVE
//Do not modify anything on or below the line above this
int main()
{
int d1;
cin >> d1;
//map values over 360 and greater back into 0-359 range
d1 %= 360;
if(d1 == NORTH) {
cout << "North" << endl;
}
else if(d1 == SOUTH) {
cout << "South" << endl;
}
else if(d1 == EAST) {
cout << "East" << endl;
}
else if(d1 == WEST) {
cout << "West" << endl;
}
else {
cout << "Error" << endl;
}
}
Patrick B. answered 05/24/21
Math and computer tutor/teacher
typedef enum _TDirection
{
EAST=0,
NORTH=90,
WEST=180,
SOUTH=270
} TDirection;
Get a free answer to a quick problem.
Most questions answered within 4 hours.
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.