Making a counter

This is a discussion on Making a counter within the C++ Programming forums, part of the General Programming Boards category; I'm trying to figure out how to get a counter that will keep score so far everything i've tried wont ...

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    19

    Making a counter

    I'm trying to figure out how to get a counter that will keep score so far everything i've tried wont work. I tried saying that if (outcome = lose) computer + 1 or something like that.. any ideas.

    Code:
    #include <iostream>
    #include <ctime>
    
    using namespace std;
    
          enum Choice { Rock, Paper, Scissors };
          enum Winner {Computer = 0, User = 0};
          enum Decision { Draw, Win, Lose };
          char DoMenu();
          void CheckWinner(int PlayerChoice);
    
    void Seed()
    { 
     srand(time(0));
    }
    
    int GetRandNum(int max)
    {
     return rand() % max;
    }
    
    int computer = 0, user = 0; 
          int main()
          {     
          
            
           
          Seed();         
                   
          cout << "Let's Play Some Rock Paper Scissor!\n" << endl;
          cout << "I Hope to God You Know How!\n" << endl;    
         
    
          char choice;
          do
          {
    
          choice = DoMenu();
          switch (choice)
          {
    
          case 'R': 
          case 'r': cout << "\nPlayer: Rock\n"; CheckWinner(Rock); break;
          case 'P': 
          case 'p': cout << "\nPlayer: Paper\n"; CheckWinner(Paper); break;
          case 'S': 
          case 's': cout << "\nPlayer: Scissors\n"; CheckWinner(Scissors); break;
          default : cout << "\n";
          }
          } while ((choice != 'Q') && (choice != 'q'));
    
          
      
          return 0;
          }
           char DoMenu()
          {
          char MenuChoice;
         
          cout << "(R)ock\n";
          cout << "(P)aper\n";
          cout << "(S)cissors\n";
          cout << "(Q)uit\n";
          cout << "----------\n";
          cout << "Choice: ";
          cout << "Computer: " << computer << " User: " << user << endl;
          cin >> MenuChoice;
    
    
          return MenuChoice;
          }
          
          void CheckWinner(int PlayerChoice)
          {
          int random = 0;     
          random = GetRandNum(3);  
          switch (random)
    
          {
          case Rock: cout << "Computer: Rock\n"; break;
          case Paper: cout << "Computer: Paper\n"; break;
          case Scissors: cout << "Computer: Scissors\n"; break;
    
          }
    
         Decision outcome;
                 
          if (PlayerChoice == Rock)
          {
          switch (random)
          {
          case Rock: outcome = Draw; break;
          case Paper: outcome = Lose; break;
          case Scissors: outcome = Win; break;
          }
          }
    
         if (PlayerChoice == Paper)
          {
          switch (random)
         {
         case Rock: outcome = Win; break;
         case Paper: outcome = Draw; break;
         case Scissors: outcome = Lose; break;
    
          }
          }
             
          if (PlayerChoice == Scissors)
         {
          switch (random)
          {
          case Rock: outcome = Lose; break;
          case Paper: outcome = Win; break;
          case Scissors: outcome = Draw; break;
    
          
          }
          }
          
    
    
          switch (outcome)
          {
          
          case Win: cout << "You Win!\n\n";break;
          case Lose: cout << "You Lose!\n\n"; break;
          case Draw: cout << "Draw\n\n"; break;
              
          
      system("PAUSE");
      
          }
          }

  2. #2
    Registered User
    Join Date
    Dec 2009
    Posts
    19
    thanks i tried something exactly like that i did user +1 guess that isn't incremental.. appreciate it.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    48
    Your
    Code:
    /*outcome stores the result 
    So at the end of void CheckWinner(int PlayerChoice) function,
    check for 
    */
    if (outcome == Win)
    		  user++;
    else if (outcome == Lose)
    		  computer++;
    No points for tie

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. making sprites
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 02-20-2010, 06:00 AM
  2. 2D diagonal counter
    By poopiepantz2525 in forum C Programming
    Replies: 4
    Last Post: 05-01-2008, 06:53 PM
  3. Making great graphics
    By MadCow257 in forum Game Programming
    Replies: 1
    Last Post: 02-20-2006, 10:59 PM
  4. thinking about making a network traffic monitor
    By jimjamjahaa in forum C++ Programming
    Replies: 9
    Last Post: 10-13-2005, 11:38 AM
  5. can you help me please?
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 01-12-2002, 08:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21