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; Whenever I run my console application, it's going to be a simple blackjack game, I get this weird command prompt ...

  1. #1
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964

    Weird command prompt error, program not working..

    Whenever I run my console application, it's going to be a simple blackjack game, I get this weird command prompt error, I think it might happen with any new precompiled header console application.

    Code:
    '\\intellimark\dfs\Home\jcoleman\My Documents\Visual Studio 2005\Projects\Blackj
    ack\Blackjack'
    CMD.EXE was started with the above path as the current directory.
    UNC paths are not supported.  Defaulting to Windows directory.
    And the program simply does not run, here is what I'm trying to do by the way, simply output the value of a card in the deck.

    Code:
    int _tmain(int argc, _TCHAR* argv[])
    {
    	Deck BlackJackDeck;
    	std::cout << BlackJackDeck.Cards[3].suit << std::endl;
    	std::cout << BlackJackDeck.Cards[3].value << std::endl;
    	return 0;
    }
    Not too complicated stuff here, but that weird console error... I'm working with Microsoft Visual Studio 2005 C++ Express Edition

    Can anyone help me?
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You are probably trying to run this from a different machine than the one you are currently using. I think this is caused by the fact that your "home" drive is not on the machine you are working. Not quite sure how you work around it, just trying to explain what the situation is.

    Guessing on a solution: You could probably try to copy the executable file to a local drive, perhaps.

    --
    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.

  3. #3
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Yeah I'm working on a network at my work desk. My documents is located on a network drive. I'll try doing what you suggested.
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  4. #4
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Okay I got it to run, without any console errors, but there is no output, I'll show you my code, could you tell if I'm doing anything incorrectly?

    Code:
    // Blackjack.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include <iostream>
    
    struct Card
    {
    	int suit;
    	int value;
    };
    
    class Deck
    {
    public:
    	Deck()
    	{
    		int x;
    		int y;
    		int z = 0;
    		while(z < 52)
    		{
    			for (y = 0; y > 3;  y++)
    			{
    				for (x = 0; x > 13; x++)
    				{
    					Cards[z].suit = y;
    					Cards[z].value = x;
    					z++;
    				}
    			}
    		}
    	}
    
    //private:
    	Card Cards[51];
    };
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	Deck BlackJackDeck;
    	std::cout << BlackJackDeck.Cards[3].suit << std::endl;
    	std::cout << BlackJackDeck.Cards[3].value << std::endl;
    	return 0;
    }
    The Deck constructor simply assigns all the cards a value with a loop, I'm going to eventually switch it to a vector instead of a simple array so I can do things like shuffling and whatnot, maybe a list would be better.

    Anyways, I'm getting no output when I run the program, any solutions?
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    There is "no output" or the output disappears so quickly that you haven't got time to read it? If it's the latter, perhaps adding a "cin.ignore()" would work. That will require some input from the console, so you have to hit enter before it exits the application.

    --
    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.

  6. #6
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Yeah I don't see anything at all in the console, not even a press enter to exit or anything like that, its just empty.

    Weird.
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  7. #7
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,793
    Code:
    for (y = 0; y > 3;  y++)
    {
        for (x = 0; x > 13; x++)
        {
            Cards[z].suit = y;
            Cards[z].value = x;
            z++;
        }
    }
    
    ...
    
    Card Cards[51];
    Whoops?
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Ah, yes. You have your comparisons in your for-loop the wrong way around, so the for-loop is never entered, and thus the z variable is never incremented. The condition for a for-loop is "while this is true", not "exit when this happens".

    Your "y" loop is too short, it should end at 3, not at 2. [again, you first need to switch the greater than to less than].

    You shouldn't really need your "while(z...)" loop - you should get 52 cards if you run a loop of 0..3 times of 0..12. [And if you get it wrong, so you don't get 52 cards, it will produce another full set of whatever your two inner loops produce, since a while loop is not testing the variable at all points, just when it reaches the top of the loop, which of course means that you would get to run both the x and the y loops fully through again, even if you only missed by one or four or such].

    --
    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.

  9. #9
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Thanks for that, I'm a bit rusty it seems after not programming anything for a year or so, I'm trying to get back into the game.

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

  10. #10
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    That will produce 39 cards.

    edit: And there is no purpose to z, unless you want to add something like:
    Code:
    if (z != 52) std::cout << "Not enough cards produced" << endl;
    or some such after your loops.

    --
    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.

  11. #11
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Okay I've fixed up everything i think, except now I'm getting a debug error when I run the program.
    Code:
    // Blackjack.cpp : Defines the entry point for the console application.
    //
    
    #include "stdafx.h"
    #include <iostream>
    
    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 < 14; x++)
    				{
    					Cards[z].suit = y;
    					Cards[z].value = x;
    					z++;
    				}
    			}
    	}
    
    
    //private:
    	Card Cards[51];
    };
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    	Deck BlackJackDeck;
    	std::cout << BlackJackDeck.Cards[3].suit << std::endl;
    	std::cout << BlackJackDeck.Cards[3].value << std::endl;
    	return 0;
    }
    The error looks like this:
    Run-Time Check failure #2 - Stack around the variable 'BlackJackDeck' was corrupted.
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  12. #12
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, now you are producing 56 cards - and you only make space for 51.

    --
    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.

  13. #13
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    Quote Originally Posted by matsp View Post
    That will produce 39 cards.

    edit: And there is no purpose to z, unless you want to add something like:
    Code:
    if (z != 52) std::cout << "Not enough cards produced" << endl;
    or some such after your loops.

    --
    Mats
    Don't I need to loop through the array of cards with Z?
    Code:
    	Card Cards[51];
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  14. #14
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    964
    OHHH I understand, I guess my math was off.... Can you help me with assigning values to a 52 card deck?

    I gave it my best shot honest, but I'm just so rusty and my brain doesn't work like it used to.

    Here is my latest code...
    Code:
    class Deck
    {
    public:
    	Deck()
    	{
    		int x;
    		int y;
    		int z = 0;
    			for (y = 0; y < 4;  y++)
    			{
    				for (x = 0; x < 14; x++)
    				{
    					Cards[z].suit = y;
    					Cards[z].value = x;
    					z++;
    				}
    			}
    	}
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  15. #15
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Shamino View Post
    Don't I need to loop through the array of cards with Z?
    Code:
    	Card Cards[51];
    Doh! Yes, of course you do. Next time I'll try too look at the code before I make comments

    You may want to add that check that I showed above, tho', at least for now, as it seems like you have a bit of a problem coming up with exactly 52 cards. [And your array still only has room for 51 cards].

    --
    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.

Page 1 of 2 12 LastLast
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