Hey all, I am trying to compile a simple program that uses the basics on enumeration types and I am having no luck. The program basically has an enumeration called Die with characteristics of the sides of a die and a variable of itself called roll. Basically the user enters a value and for the side of the die and the program displays the output. Here is the code....
and here is what the compiler gives me.....Code://Die Enumeration Example //May 2, 2007 //Demos enum with a simple program where the user selects the side of a die #include <iostream> using namespace std; enum Die{side1, side2, side3, side4, side5, side6}; // declare Die enumeration and it's variable roll int main() { enum Die Roll; int c; // user input variable bool match = false; //test for match cout << "Die" << endl; //Program info cout << "Created By ....." << endl; cout << "May 2, 2007" << endl; cout << endl; cout << "Please enter a roll number: "<< endl; cin >> c; for (Roll = side1, Roll <= side6, Roll++) //find the value entered by the user { if (c - Roll = 0) { match = true; //if there's a match exit loop break; } } if (match = true) //if value entered matches a side of the die { //display corresponding result switch (Roll) { case side1: case side2: case side3: case side4: case side5: cout << endl << "Sorry! You must roll a 6." << endl; case side6: cout << endl << "6 that's great, you can go." << endl; } else cout < endl << "No! That's not (1 - 6)!" << endl; } //Exit Sequence cout << "Please press enter to continue..." << endl; cin.ignore(1); cin.get(); return 0; }
c:\documents and settings\owner\my documents\visual studio 2005\isaakj\assignment4\die\die\die.cpp(22) : error C2146: syntax error : missing ';' before identifier 'cout'
c:\documents and settings\owner\my documents\visual studio 2005\isaakj\assignment4\die\die\die.cpp(30) : error C2676: binary '++' : 'Die' does not define this operator or a conversion to a type acceptable to the predefined operator
c:\documents and settings\owner\my documents\visual studio 2005\isaakj\assignment4\die\die\die.cpp(30) : error C2143: syntax error : missing ';' before ')'
c:\documents and settings\owner\my documents\visual studio 2005\isaakj\assignment4\die\die\die.cpp(30) : error C2143: syntax error : missing ';' before ')'
c:\documents and settings\owner\my documents\visual studio 2005\isaakj\assignment4\die\die\die.cpp(32) : error C2106: '=' : left operand must be l-value
c:\documents and settings\owner\my documents\visual studio 2005\isaakj\assignment4\die\die\die.cpp(50) : error C2181: illegal else without matching if
c:\documents and settings\owner\my documents\visual studio 2005\isaakj\assignment4\die\die\die.cpp(51) : error C2563: mismatch in formal parameter list
I was under the understanding that enum defaulted to int type if another type wasn't declared but the errors state that Roll (which should be int) can't be compared to c (int). I can't seem to figure it out. Do you guys have any ideas.....



LinkBack URL
About LinkBacks


