i need little help of urs in the above code, RightFrom Function is perfectly working but there is a logic bug in LeftFrom Function.
when i m sending North as argument the result from LeftFrom is -1 but i need 0. help me to solve this issue.

#include <iostream>
using namespace std;
enum direction{
	North,
	East,
	South,
	West,
};

direction RightFrom(direction d){
	return direction((d+1) % 4);
}

direction LeftFrom(direction d){
	return direction((d-1) % 4);
}

void main(){
	cout << RightFrom(West) << endl; // West = 4 and it will output 0 as required
	
	cout << LeftFrom(North) << endl; // North = 0 and it will output -1 ( but i need the result 0)	
}

how about this: return (d-1) < 0 ? North : d-1; No need for the mod operator.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.