Thread: .exe not working?

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    10

    Exclamation .exe not working?

    I have made another program, a blackjack. I have compiled it with no problems but it seems that .exe is not working.

    Here's the code:
    Code:
    #include <iostream>
    #include<conio.h>
    #include<stdlib.h>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
     int cash=10000, hit, bet, decide1, decide2, enemy;
     int pips1, pips2, pips3, pips4, suit1, suit2, Ace=11, Jack=10, Queen=10, King=10, Spades, Clubs, Diamonds, Hearts;
     int value=pips1+pips2+pips3+pips4;
     char retry, y, n, h, s, d;
     
     
     void clrscr();
       std::cout<<"Welcome to Blackjack. You'll start with $" << cash << "\n";
       
      betting:
       std::cout<<"You have $"  << cash << ".\nPlace your bet.\n";
       std::cin>>bet;
       //if(cash>=0)
       //{
       //goto lost;
       //}  
       if(cash<bet)
       {
       std::cout<<"You do not have enough money. Please place a lower bet.\n";
       goto betting;
       }   
       else
       {
       cash=cash-bet;
       std::cout<<"Bet: $" << bet << " Cash in hand: $" << cash << "\n";
       goto player;
       }
       
      do 
      {
      player:   
      std::cout<<"We will draw 2 cards from the deck\n";  
      int randomize();
       pips1=(int)(rand()%13+1);
       pips1==1==Ace;
       pips1==11==Jack;
       pips1==12==Queen;
       pips1==13==King;
      int randomize();
       suit1=(int)(rand()%4+1);
       suit1==1==Spades;
       suit1==2==Clubs;
       suit1==3==Diamonds;
       suit1==4==Hearts;
      int randomize();
       pips2=(int)(rand()%13+1);
       pips2==1==Ace;
       pips2==11==Jack;
       pips2==12==Queen;
       pips2==13==King;
      int randomize();
       suit2=(int)(rand()%4+1);
       suit2==1==Spades;
       suit2==2==Clubs;
       suit2==3==Diamonds;
       suit2==4==Hearts; 
       
      if(pips1==Ace)
       {
       pips1==11;
       }
      if(pips2==Ace)
       {
       pips2==11;
       }
      
     
      std::cout<<"You have drawn" << pips1 << "of" << suit1 << "and" << pips2 << "of" << suit2 << ".\nA value of" << value << "./n";
      if(value==21)
      {
      std::cout<<"Blackjack! You won" << bet*2 << "./n";
      goto result;
      }
      else if(value>=22)
      {
      std::cout<<"You lost!";
      goto betting;
      }
      else
      {
      std::cout<<"Hit(h)? Double(d)? Stand(s)?\n";
      std::cin>>decide1;
      }
      
      decision1:
        if(decide1==h)
         {
        pips4==0;              
        goto hit;
        }
        else if(decide1==d)
        {
        goto dbl;
        }
        else if(decide1==s)
        {
        pips3==0;
        pips4==0;
        goto stand;
        }
        else
        {
        goto decision1;
        }
        
      decision2:
        std::cout<<"Hit(h)? Stand(s)?\n";
        std::cin>>decide2;
        if(decide2==h)
         {
        goto hit2;
        }
        else if(decide2==d)
        {
        std::cout<<"You can't do a double now.\n";
        goto decision2;
        }
        else if(decide2==s)
        {
        goto stand;
        }
        else
        {
        goto decision2;
        }
        
     result:
        if(value>enemy||value==21)
        {
        cash=cash+bet*2;
        std::cout<<"You win $" << bet*2 << "!\n\n"; 
        goto betting;
        }        
        else if(value<enemy||value>=22)
        {
        std::cout<<"You lost!\n\n";
        goto betting;
        }
            
     hit:
    	int randomize();
        pips3=(int)(rand()%13+1);
        pips3==1==Ace;
        pips3==11==Jack;
        pips3==12==Queen;
        pips3==13==King;
    	value=value+pips3;
    	std::cout<<"Value is now " << value << ".\n";
    	if(value==21)
    	{
        goto result;
        }
        else
        {
    	goto decision2;
        }
        
     hit2:
        int randomize();
        pips4=(int)(rand()%13+1);
        pips4==1==Ace;
        pips4==11==Jack;
        pips4==12==Queen;
        pips4==13==King;
    	value=value+pips4;
    	std::cout<<"Value is now " << value << ".\n";
    	if(value==21)
    	{
        goto result;
        }
        else
        {
    	goto decision2;
        } 	
        
     dbl:
        int randomize();
        pips3=(int)(rand()%13+1);
        pips3==1==Ace;
        pips3==11==Jack;
        pips3==12==Queen;
        pips3==13==King;
    	
       	int randomize();
        pips4=(int)(rand()%13+1);
        pips4==1==Ace;
        pips4==11==Jack;
        pips4==12==Queen;
        pips4==13==King;
    	value=value+pips3+pips4;
    	std::cout<<"Value is now " << value << ".\n";
    	goto result;
    
    stand:
        goto result;
        
    computer:
        int randomize();
        enemy=(int)(rand()%13+16);
        
        
        
        } while(!cash);
        lost:  
        std::cout<<"Thank you for playing Guess Game.\nPlay again? (y/n)";
        std::cin>>retry;
        if(retry==y)
        {
        cash=cash+10000;
        goto betting;
        }    
        else if(retry!=y||retry!=n)
        {
        goto lost;
        }
        else
        {
        
        }while(retry=='y' || retry=='Y');
        return 0;
    }

  2. #2
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    What happens when you try to run it?
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    10
    Absolutely nothing. Nothing blinks but when I look at the taskmgr(Windows Task Manager) it's running.

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    1) Try to get rid of all the goto's. goto is not a keyword that you'd normally use for program flow control (these are if, else, for, while, do and switch).

    2)
    Code:
    pips3==1==Ace;
    What exactly are statements like these supposed to do? (They do nothing.)

    3)
    Code:
    int randomize();
    This, and similar things are not function calls, but declarations, that there exists a function called randomize that takes no arguments and returns an int.
    If you have a function called randomize and you want to call it, drop the int.

    Edit:
    4) Try to get rid of non-standard "conio.h". Other people may not have it and can't try to compile your code. Clearing the screen is no that important.

    5)
    While it is understandable that a beginner has enough trouble with deciphering compiler errors, it wouldn't hurt to turn on its warnings (somewhere in the compiler settings). With DevC++ I got the following warnings from your code:

    Untitled1.cpp:43: warning: statement has no effect
    ... same thing on many other lines

    Untitled1.cpp:9: warning: unused variable 'hit'

    Untitled1.cpp:205: warning: label `computer' defined but not used

    Untitled1.cpp: At global scope:

    Untitled1.cpp:8: warning: unused parameter 'argc'
    Untitled1.cpp:8: warning: unused parameter 'argv'

    Untitled1.cpp: In function `int main(int, char**)':
    Untitled1.cpp:9: warning: 'enemy' might be used uninitialized in this function
    Untitled1.cpp:10: warning: 'pips1' might be used uninitialized in this function
    Untitled1.cpp:10: warning: 'pips2' might be used uninitialized in this function
    Untitled1.cpp:10: warning: 'pips3' might be used uninitialized in this function
    Untitled1.cpp:10: warning: 'pips4' might be used uninitialized in this function
    Untitled1.cpp:12: warning: 'h' might be used uninitialized in this function
    Untitled1.cpp:12: warning: 's' might be used uninitialized in this function
    Untitled1.cpp:12: warning: 'd' might be used uninitialized in this function
    Basically, this all says, there is no hope your code would do anything useful as it is and as long as you don't fix the listed problems.
    Last edited by anon; 03-25-2007 at 08:48 AM.

  5. #5
    Registered User
    Join Date
    Mar 2007
    Posts
    10
    Help me with this I'm just starting today because I needed to.

    1. I don't know how to make it work without utilizing goto's. Mind if you give me an example from my codes.

    2. I don't know if that's correct. What I mean by that is when "1" is called by the randomize, it will also be known as Ace rather than just 1.

    3. I can't remove int. Bloodshed(compiler) needs every function defined.

  6. #6
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    I'm using MSVC 8. When I compile I get about 47 warnings. When I run it, I get a runtime error saying pips1 is being used without being defined.

    It looks to me like you coded like a madman, without taking your time and compiling after you've finished a section of code. Now you have the long journey of looking through your mess of a code, to try and find what's happening.
    Videogame Memories!
    A site dedicated to keeping videogame memories alive!

    http://www.videogamememories.com/
    Share your experiences with us now!

    "We will game forever!"

  7. #7
    Registered User
    Join Date
    Mar 2007
    Posts
    10
    Sorry dude. I have to make this as fast as possible. I didn't have any time to read books, in fact. Got to pass this 2 days from now.

  8. #8
    Registered User Noir's Avatar
    Join Date
    Mar 2007
    Posts
    218
    2 days is more than enough to take your time and do it right. Pros have to get a hell of a lot more done in 2 days than this, so you should get used to the pressure now.

  9. #9
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Quote Originally Posted by deng17
    Sorry dude. I have to make this as fast as possible. I didn't have any time to read books, in fact. Got to pass this 2 days from now.
    You have two choices: either you read some tutorials and try to learn something, or write meaningless lines of codes and not make it.

  10. #10
    Registered User
    Join Date
    Mar 2007
    Posts
    10
    Actually I only have hours left.

    One hour left it will be only for one day and tomorrow I have school for the whole day.

    Right now I'm rewriting the code.

  11. #11
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Right now I'm rewriting the code.
    This time, try to see the difference between assinging and comparing for equality, and between function declarations and calls.

    And hopefully rewriting the code doesn't mean retyping something similar. Write a few lines of code, compile it and verify that they indeed do what you expect, then write some more. Etc.

  12. #12
    Lean Mean Coding Machine KONI's Avatar
    Join Date
    Mar 2007
    Location
    Luxembourg, Europe
    Posts
    444
    Quote Originally Posted by deng17
    Actually I only have hours left.

    One hour left it will be only for one day and tomorrow I have school for the whole day.

    Right now I'm rewriting the code.
    Good Luck.

    Please remember that for beginners, it is easier to code a little piece of code only and then test it thoroughly, before continuing. That should reduce the chance to find unexplainable errors later on.

  13. #13
    Registered User
    Join Date
    Mar 2007
    Posts
    10
    Oh yeah how can I return to a code if I'll not be using goto????

    For example,

    I have lost the round and want to return to the 1st stage(which is betting) how can I go back there?

  14. #14
    Registered User Noir's Avatar
    Join Date
    Mar 2007
    Posts
    218
    Use a loop?

  15. #15
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Try using a function call. Place that first round in a function and call it when you need it.
    Double Helix STL

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 12-09-2008, 11:09 AM
  2. .exe size with MinGW
    By Stabbsy in forum C++ Programming
    Replies: 3
    Last Post: 11-16-2006, 06:07 AM
  3. Program Not working Right
    By raven420smoke in forum C++ Programming
    Replies: 2
    Last Post: 09-16-2005, 03:21 AM
  4. Trying to eject D drive using code, but not working... :(
    By snowfrog in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2005, 07:47 PM
  5. cygwin -> unix , my code not working properly ;(
    By CyC|OpS in forum C Programming
    Replies: 4
    Last Post: 05-18-2002, 04:08 AM