Getting an error on the cin>> classes. On the operand sign >>. What i'm trying to do here is asking the user for his favorite subject, in which they will type history, math, geometry, pe, or science. Once they do that. under void display function, I will use that subject parameter and do the following.
/Enumeration for classes
enum subjects { history, math, geometry, pe, science};
// Void function display and get the favorite class from the user
void getfavoritesubject (subjects & classes)
{
cout<<"What is your favorite subject";
cin >> classes; //get an error on ">>" operand. What would be wrong here?
}
void choice (subjects classes)
{
if (classes == history)
cout<<"Your In history";
}
int _tmain(int argc, _TCHAR* argv[])
{
subjects replacesubject;
getfavoritesubject(replacesubject);
_getch();
return 0;
}
I changed my code quite a bit. My problem is how do I convert a string to enumeration type. If I can't then how do I save the string savegetfav under choosessubject? :(
//Enumeration for classes
enum courses { history, math, geometry, pe, science};
// Void function display and get the favorite class from the user
string getfavoritesubject ()
{
cout<<"What is your favorite subject";
string subject;
cin >> subject; //get an error on ">>" operand. What would be wrong here?
return subject;
}
void choice (courses classeschosen)
{
if (classeschosen == history)
cout<<"Your In history";
}
int _tmain(int argc, _TCHAR* argv[])
{
string savegetfav;
savegetfav=getfavoritesubject();
courses choosesubject;
choosesubject=savegetfav;
switch ( choosesubject)
{
case'math':
choosesubject=math;
}
_getch();
return 0;
}