CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2011
    Posts
    0

    Slot Machine Help please?

    whenever i run this code on devc++ my compiler crashes its just the beginning but can somebody help me along through this?

    code:


    Code:
    /**
     *    @author mgawronski
     *    @version 2/15/11    
     *
     *    Code Description:
     *
     */
    #include <iostream>            //Allows user to interact with application
    #include <stdlib.h>         //used to extract largest int value
    #include <time.h>           //used to extract time from internal clock
    #include <cstdlib>
    #include <conio.h>
    
    using namespace std;        //Introduces namespace std
    
    int Wager;
    int Chips = 1000;
    int Fruit;
    string FruitName;
    string WheelOne;
    string WheelTwo;
    string WheelThree;
    
    void Intro();
    //pre:
    //post:
    void Intro()
    {
        cout<<"*********************************************\n"
            <<"---------------------------------------------\n"
            <<"***********Welcome to DJM's Casino***********\n"
            <<"---------------Enjoy The Slots---------------\n"
            <<"*********************************************\n\n";
    }
    
    void Exit();
    //pre:
    //post:
    void Exit()
    {
        cout<<"*********************************************\n"
            <<"---------------------------------------------\n"
            <<"******Thanks For Visiting DJM's Casino*******\n"
            <<"-----------------Visit Again-----------------\n"
            <<"*********************************************\n\n";
    }
    
    int Bet();
    //pre:
    //post:
    int Bet()
    {
        cout<<"You have $"<<Chips<<endl;
        cout<<"Place your bet (Whole Number): ";
        cin>>Wager;
        Chips = Chips - Wager;
    }
    
    int Win();
    //pre:
    //post:
    int Win()
    {
        
    }
    
    string GetFruit();
    //pre:
    //post:
    string GetFruit()
    { 
            Fruit = (rand()&#37;3)+1;
        
            if(1 == Fruit)
            {
                FruitName = "Cherry";
            }
                else if(2 == Fruit)
                {
                    FruitName = "Orange";
                }
                else if(3 == Fruit)
                {
                    FruitName = "Apple";
                }
            else
            {
               cout<<"How did this happen?";
            }
    }
    
    void Play();
    //pre:
    //post:
    void Play()
    {
        Intro();
        Bet();
    
        cout<<"Press Enter to Begin Slots\n";
        getch();
    
        GetFruit();
        WheelOne = FruitName;
        GetFruit();
        WheelTwo = FruitName;
        GetFruit();
        WheelThree = FruitName;
    
        cout.setf(ios::fixed);
        cout.width(30);
        cout<<WheelOne<<"   "<<WheelTwo<<"   "<<WheelThree<<endl;
    
        Exit();
    }
    
    int main()
    {
        srand(time(NULL));        //initialize random seed
        Play();
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    Last edited by Marc G; February 20th, 2011 at 04:52 AM. Reason: Added code tags

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Slot Machine Help please?

    Your compiler crashes?
    What do you mean?
    Does it give an error?
    If so, which error?

    Also, you are missing a include for <string>
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Slot Machine Help please?

    ... after over 11 years......
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Tags for this Thread

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured