So my problem goes like this, i have to enter a number from 1-7 and for each respective number i have to print a letter from the word english(e is for 1, n is for 2, etc.) Here is my idea:
#include <iostream>
using namespace std;
int main()
{
enum eng {e='e', n='n',g,l,i,s,h}
};
int x;
cout << "dati x\n";
cin >> x;
if (x >= 0 && x <= 7)
eng val = static_cast<eng>(x);
cout << x;
}
i want the number ( x ) to be converted to its respective letter from the eng type, but the conversion gives me back the number( if i put 1 it gives me 1, if i put 2 it gives me 2) i tried assigning an char value to e and n in eng , to see what happens ,but its the same result, i know i can use switch,but i want to try to get this working
const char* eng = "english";...cout << eng[x];?x >=0 && x <=7has an off-by-one error. If your range is 1-7 then usex >= 1 && x <= 7. If your range is 0-6 then you usex >= 0 && x < 7. The above example from Alan assumes you're using 0-6. However, it is valid with 0-7 because of the string contains a NUL terminator..