Note that there are some explanatory texts on larger screens.

plurals
  1. POI cannot seem to get Visual C++ Express (2010) to recognize enum class
    primarykey
    data
    text
    <p>Hi guys (and girls), I am working to re-familiarize myself with C++ after using only Python for too long. I have written a small program with MS Visual C++ 2010 Express edition and I have looked all over the place for a culprit for why the compiler doesn't seem to like my usage of enum class Choice. The compiler complains that a namespace with this name does not exist. Now, I should say that all previous C/C++ code I have written was in an academic setting thus I was using the full IDE. Anyway, I am appending the code below and please forgive me if this is the incorrect method on which to post it. If it is please refer me to the correct method and I will employ it henceforth. Thank you, in advance, for any help or insight anyone might be able to lend. The code is as follows. </p> <pre><code>#include"stdafx.h" #include&lt;iostream&gt; #include&lt;string&gt; #include&lt;ctime&gt; using namespace std; enum class Choice { rock, paper, scissors }; using namespace Choice;** Choice player_choice; //holds user's move Choice machine_choice; //holds machine's move string words[3] = {"rock","paper","scissors"}; Choice get_machine_choice(); void decide_winner(); string get_msg(Choice winner); int rand0toN1(int n); int main(int argc, char *argv[]) { srand(time(NULL)); //set randomization string input_str; int c; while (true) { cout &lt;&lt; "Enter Rock, Paper, Scissors, or Exit: "; getline(cin, input_str); if (input_str.size() &lt; 1) { cout &lt;&lt; "Sorry, I don't understand that.\n"; continue; } c = input_str[0]; if (c == 'R' || c == 'r') player_choice = rock; else if (c == 'P' || c == 'p') player_choice = paper; else if (c == 'S' || c == 's') player_choice = scissors; else if (c == 'E' || c == 'e') break; else { cout &lt;&lt; "Sorry, I don't understand that.\n"; continue; } machine_choice = get_machine_choice(); int p = (int) player_choice; int c = (int) machine_choice; cout &lt;&lt; "You Choose " &lt;&lt; words [p]; cout &lt;&lt; "," &lt;&lt; endl; cout &lt;&lt; "I choose " &lt;&lt; words [c]; cout &lt;&lt; "," &lt;&lt; endl; decide_winner(); } return EXIT_SUCCESS; } Choice get_machine_choice() { int n = rand0toN1(3); if (n == 0) return rock; if (n == 1) return paper; return scissors; } void decide_winner() { if (player_choice == machine_choice) { cout &lt;&lt; "Reult is a tie.\n\n"; return; } int p = static_cast&lt;int&gt;(player_choice); int c = static_cast&lt;int&gt;(machine_choice); if (p - c == 1 || p - c == -2) { cout &lt;&lt; get_msg(player_choice); cout &lt;&lt; "Unfortunantly, you win...\n"; } else { cout &lt;&lt; get_msg(machine_choice); cout &lt;&lt; "I WIN, BEEEATCH!!!!\n"; } cout &lt;&lt; endl; } string get_msg(Choice winner) { if (winner == rock) return string("Rock smashes scissors, beeatch..."); else if (winner == paper) return string("You know what paper does to rock, COVERAGE!!..."); else return string("CHOP! Scissors cut paper!!...."); } int rand0toN1(int n) { return rand() % n; } </code></pre> <p>Thank you again for taking the time to help me out. I seem to remember declaring classes quite often using C++ and cannot figure out why it will not recognize it. Thanks again for taking the time. Court (Clemson University, SC)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload