Results 1 to 9 of 9

Thread: Card Counter

  1. #1
    Senior Member
    Join Date
    May 2004
    Posts
    206

    Card Counter

    I got bored today, so I made a program to count cards. Tell me what you think of it.

    Code:
    #include <iostream>
    #include <stdlib.h>
    
    short int diamonds[13];
    short int hearts[13];
    short int clubs[13];
    short int spades[13];
    short int card;
    short int again = 0;
    short int i = 0;
    
    void setup();
    void MainScreen();
    
    int main()
    {
          //Introduction
          system("cls");
          cout << "\n\n\t\t\t    Counting Cards";
          cout << "\n\n\n\n\t\t\t  By: Jared Stewart.\n\n\n\n\t\t     ";
          system("PAUSE");
          system("cls");
          cout << "A 0 means the card has already been played,\nand anything else means it hasn't.\n\n";
          system("PAUSE");
          MainScreen();
          return 0;
    }
    
    void setup()
    {
          //Setting up the variables
          for(i = 0; i < 13; i++)
          {
          diamonds[i] = i + 1;
          hearts[i] = i + 14;
          clubs[i] = i + 27;
          spades[i] = i + 40;
          }
    return;
    }
    
    void MainScreen()
    {
    //Main Screen
          setup();
           i = 0;
          do
          {
          system("cls");
          cout << "For a new deck, type 53.  To exit, type 54.\n\n";
          cout << "          2   3   4   5   6   7   8   9   10   J   Q   K   A\n";
         /**************Diamonds***************/
         cout << "\nDiamonds  ";
          for ( i = 0; i < 8; i++)
          {
          cout << diamonds[i];
          cout << "   ";   //Three spaces
         }
         cout << " " << diamonds[8] << "   "; //To compensate for the two digits in 10.
          for ( i = 9; i < 13; i++)
          {
          cout << diamonds[i];
          cout << "  ";   //Two spaces
         }
         cout << endl;
         /**************Hearts***************/
          cout << "Hearts    ";
                for ( i = 0; i < 8; i++)
          {
          cout << hearts[i];
          cout << "  ";
         }
         cout << hearts[8] << "   "; //To compensate for the two digits in 10.
          for ( i = 9; i < 13; i++)
          {
          cout << hearts[i];
          cout << "  ";
         }
         cout << endl;
              /****************Clubs****************/
          cout << "Clubs     ";
                for ( i = 0; i < 8; i++)
          {
          cout << clubs[i];
          cout << "  ";
         }
         cout << clubs[8] << "   "; //To compensate for the two digits in 10.
          for (i = 9; i < 13; i++)
          {
          cout << clubs[i];
          cout << "  ";
         }
         cout << endl;
                   /****************Spades****************/
          cout << "Spades    ";
                for (i = 0; i < 8; i++)
          {
          cout << spades[i];
          cout << "  ";
         }
         cout << spades[8] << "   "; //To compensate for the two digits in 10.
          for (i = 9; i < 13; i++)
          {
          cout << spades[i];
          cout << "  ";
         }
         cout << endl << "Enter a Card: ";
         cin >> card;
              /***********************************/
         switch(card)
         {
         case 1:
         diamonds[0] = 0;
         break;
         case 2:
         diamonds[1] = 0;
         break;
         case 3:
         diamonds[2] = 0;
         break; 
         case 4:
         diamonds[3] = 0;
         break;
         case 5:
         diamonds[4] = 0;
         break;
         case 6:
         diamonds[5] = 0;
         break;  
         case 7:
         diamonds[6] = 0;
         break;
         case 8:
         diamonds[7] = 0;
         break;
         case 9:
         diamonds[8] = 0;
         break;
         case 10:
         diamonds[9] = 0;
         break;
         case 11:
         diamonds[10] = 0;
         break;
         case 12:
         diamonds[11] = 0;
         break;
         case 13:
         diamonds[12] = 0;
         break;
         case 14:
         hearts[0] = 0;
         break;
         case 15:
         hearts[1] = 0;
         break;
         case 16:
         hearts[2] = 0;
         break;
         case 17:
         hearts[3] = 0;
         break;
         case 18:
         hearts[4] = 0;
         break;
         case 19:
         hearts[5] = 0;
         break;
         case 20:
         hearts[6] = 0;
         break;
         case 21:
         hearts[7] = 0;
         break;
         case 22:
         hearts[8] = 0;
         break;
         case 23:
         hearts[9] = 0;
         break;
         case 24:
         hearts[10] = 0;
         break;
         case 25:
         hearts[11] = 0;
         break;
         case 26:
         hearts[12] = 0;
         break;
         case 27:
         clubs[0] = 0;
         break;
         case 28:
         clubs[1] = 0;
         break;
         case 29:
         clubs[2] = 0;
         break;
         case 30:
         clubs[3] = 0;
         break;
         case 31:
         clubs[4] = 0;
         break;
         case 32:
         clubs[5] = 0;
         break;
         case 33:
         clubs[6] = 0;
         break;
         case 34:
         clubs[7] = 0;
         break;
         case 35:
         clubs[8] = 0;
         break;
         case 36:
         clubs[9] = 0;
         break;
         case 37:
         clubs[10] = 0;
         break;
         case 38:
         clubs[11] = 0;
         break;
         case 39:
         clubs[12] = 0;
         break;
         case 40:
         spades[0] = 0;
         break;
         case 41:
         spades[1] = 0;
         break;
         case 42:
         spades[2] = 0;
         break;
         case 43:
         spades[3] = 0;
         break;
         case 44:
         spades[4] = 0;
         break;
         case 45:
         spades[5] = 0;
         break;
         case 46:
         spades[6] = 0;
         break;
         case 47:
         spades[7] = 0;
         break;
         case 48:
         spades[8] = 0;
         break;
         case 49:
         spades[9] = 0;
         break;
         case 50:
         spades[10] = 0;
         break;
         case 51:
         spades[11] = 0;
         break;
         case 52:
         spades[12] = 0;
         case 53:
         MainScreen();
         break;
         case 54:
         i = 1;
         break;
         }
         } while (i != 1);
    return;
    }
    It is better to die on your feet than to live on your knees.

  2. #2
    Don't take this the wrong way, but that is some of the worst code I have ever seen. I am sitting here looking at it and first thing I notice is that it is set for windows, cls doesn't work on Unix/Linux systems.

    Second thing I notice, from playing with it, is that there is no check to see if someone puts in something besides a card.


    I accidentally typed clear, and all I saw was your loop take over my screen.

    Dude take a better look at your code, play with it more. Then once you have it fully working then post it.

    Oh, and add using namespace std;

  3. #3
    Senior Member
    Join Date
    May 2004
    Posts
    206
    It works perfectly fine if you use it correctly and on the correct platform.
    It is better to die on your feet than to live on your knees.

  4. #4
    Elite Hacker
    Join Date
    Mar 2003
    Posts
    1,407
    Originally posted here by Jareds411
    It works perfectly fine if you use it correctly and on the correct platform.
    So you're just going to assume all users are smart and enter everything in perfectly how it should be? Ouch, I see bad things happening there.

  5. #5
    Agh.... So let me get this correct. You are not going to say what the right platform is, and you expect everyone to use it on that platform?

    Wow.


    Now as for using it correctly. I wouldn't intend to use it at all. I was trying to help you out with your code. If you are going to take some Innocent advice, and say **** it. Don't take it. I am just letting you know your code is leaving a little to be desired.

    Besides the fact that you are missing a couple things, you have a algorithm that is a bit lacking.

    You might want to get a book called. Introduction to Algorithms.

    Wait, nvm. You don't care for criticism. Because as you said you code does what it's suppose to do.

  6. #6
    Senior Member
    Join Date
    Apr 2004
    Posts
    1,024
    I will give you an analogy to show you why your code needs some reworks.

    Can you drive faster with a '82 semi that has an oil leak and a walnut in one exaust pipe or a ferarri? Your code has lots of little problems, kind of like the semi. It also has certain problems that keep it from driving on all roads. It goes slower because it was not built to be fast.

    Edit: Damn that analogy sucked... Maybe someone else can provide a better one, but it proves the point does it not?
    [H]ard|OCP <--Best hardware/gaming news out there--|
    pwned.nl <--Gamers will love this one --|
    Light a man a fire and you\'ll keep him warm for a day, Light a man ON fire and you\'ll keep him warm the rest of his life.

  7. #7
    Senior Member
    Join Date
    May 2004
    Posts
    206
    I appreciate constructive criticism. However, not running on Linux is not a flaw in my code. That's like saying there's a bug in the linux 'whois' command because you can't run it on windows.
    Whoever said that I should check to make sure the input is a card, I'm working on that now. That is something I consider constructive criticism.
    It is better to die on your feet than to live on your knees.

  8. #8
    Actually, there is a whois for windows. It's sam spade. Your code does run on Unix/Linux, the cls and pause commands don't though. They are windows commands.

    The linux command for cls is clear. I am assuming what you want for pause is sleep.

  9. #9
    Senior Member
    Join Date
    May 2004
    Posts
    206
    My point wasn't that there isn't a whois for windows, but that the one intended for linux won't work on windows.
    It is better to die on your feet than to live on your knees.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •