Image

Imagenaviduk wrote in Imagecpp

I wasn't sure if I'm meant to post this here or not - I'm an amateur programmer and this is a pretty basic program. Still, if anyone can help it's greatly appreciated.


#include <iostream>
using namespace std;

int main()
{
  enum num {ZERO, ONE, TWO, THREE, FOUR};
  num val = THREE;

  cout << "Rank no. " << val;

  return 0;
}


As one would expect, the output is "Rank no. 3" What I want to know is, is it possible to assign an integer value to "val" (for instance, 2), and have it output it in letters in accordance with the enumeration? So for instance if you assigned 2 to "val", you would get an output of "TWO". Is this possible to do? If so, how does one go about it?

Once again, sorry if this is in the wrong place, just tell me if it is.

Thanks for the help.