Weird command prompt error, program not working..

This is a discussion on Weird command prompt error, program not working.. within the C++ Programming forums, part of the General Programming Boards category; Actually I think you are maybe wrong... because 13x4=52......

  1. #16
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Actually I think you are maybe wrong... because 13x4=52...
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  2. #17
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,672
    Code:
    class Deck
    {
    public:
        Deck()
        {
            int x;
            int y;
            int z = 0;
            for (y = 0; y < 4;  y++)
            {
                for (x = 0; x < 13; x++)
                {
                    Cards[z].suit = y;
                    Cards[z].value = x;
                    z++;
                }
            }
        }
    
    
    //private:
    	Card Cards[52];
    };
    I used to be an adventurer like you... then I took an arrow to the knee.

  3. #18
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,681
    But 4 * 14 is 56!

    And your second loop will run 0..13, which is 14 iterations, not 13, just like your first loop runs 0..3, which is 4 iterations.

    [Just because I made one mistake doesn't mean that everything else I said is wrong!]

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #19
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    awesome its all fixed up now, thanks for your help guys

    Code:
    struct Card
    {
    	int suit;
    	int value;
    };
    
    class Deck
    {
    public:
    	Deck()
    	{
    		int x;
    		int y;
    		int z = 0;
    			for (y = 0; y < 4;  y++)
    			{
    				for (x = 0; x < 13; x++)
    				{
    					Cards[z].suit = y;
    					Cards[z].value = x;
    					z++;
    				}
    			}
    	}
    
    
    //private:
    	Card Cards[52];
    };
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. weird things with my linked list of queue
    By -EquinoX- in forum C Programming
    Replies: 3
    Last Post: 11-22-2008, 10:23 PM
  2. some really weird problems with string !
    By mellisa in forum C++ Programming
    Replies: 2
    Last Post: 01-20-2003, 03:56 AM
  3. cygwin -> unix , my code not working properly ;(
    By CyC|OpS in forum C Programming
    Replies: 4
    Last Post: 05-18-2002, 04:08 AM
  4. Direct Draw weird stuff
    By Magos in forum C++ Programming
    Replies: 6
    Last Post: 04-24-2002, 04:39 AM
  5. getting current working filename
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 04-17-2002, 03:42 PM

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