Wrox Programmer Forums
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old February 1st, 2006, 11:36 PM
Registered User
 
Join Date: Feb 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to FAdirtbmx
Default My Coin Flip Game


ok so im doing this game thing and i wanted to share w/ u guys...so i guess put it in ur compile and yea do watever i DO know there will be errors but i dont have a compiler on this comp. but im downloading one now i made this prog @ skool report errors u experience thanxs!

#include<iostream.h> // FA
#includ<string.h> // 2/1/06
#include<time.h> // pd 5

void init_mm(); // these functions
int number_range(int from, int to); // go to
int number_mm(void); // the random
static int rgiState[2 + 55]; // number generator leave them alone

void print_welcome();
void_getflip();
void get_random(int random, int &head, int &tail);
void running_display(int &head, int &tail);
void display(int head, int tail);

int head = 0; // global varriables
int tail = 0;


void main()
{
    int random;
    int head;
    int tail;

    print_welcome();
    do
    {
        get_flip();
        get_random(random, head, tail);
        running_display(head, tail);
    }
    while(head != 10);

    do
    {
        display(head, tail);
    }
    while(head == 10

}


void print_welcome()
{
    cout << "Welcome to the Coin Flip Race. -FA" << '\n';
}


void get_flip()
{
    char get[1];

    cout << "Enter 'f' to flip the coin." << '\n';
    cin.get(get, 1);
    cin.ignore(80, '\n');
}


void get_random(int random, int &head, int &tail)
{
    init_mm();
    random = number_range(1, 2);

    cout << "The coin is flipping." << '\n';
    cout << "coin flips here" << '\n';

    if (random == 1)
    {
        head = head + 1;
        cout << "The coin landed on heads." << '\n';
        cout << '\n';
        cout << '\n';
    }
    else
    {
        tail = tail + 1;
        cout << "The coin landed on tails." << '\n';
        cout << '\n';
        cout << '\n';
    }
}


void display(int head, int tail)
{
    cout << "Heads: " << head << '\n';
    cout << "Tails: " << tail << '\n';
}


void running_display(int &head, int &tail)
{
    cout << "Heads: " << head << '\n';
    cout << "Tails: " << tail << '\n';
}


// random number generator below


int number_mm(void)
{
    int *piState;
    int iState1;
    int iState2;
    int iRand;
    piState = &rgiState[2];
    iState1 = piState[-2];
    iState2 = piState[-1];
    iRand = (piState[iState1] + piState[iState2])
                         &((1 << 30)- 1);
    piState[iState1] = iRand;
    if(++iState1 == 55)
        iState1 = 0;
    if(++iState2 == 55)
        iState2 = 0;
    piState[-2] = iState1;
    piState[-1] = iState2;
    return iRand >> 6;
}

// Generate a random number.

int number_range(int from, int to)
{
    int power;
    int number;
    if((to = to - from + 1) <= 1)
        return from;
    for(power = 2; power < to; power <<=1)
        ;
    while((number = number_mm() & (power - 1) ) >=to)
        ;
    return from + number;
}

// This is the Mitchell-Moore algorithm for Knuth Volume II.

void init_mm()
{
    int *piState;
    int iState;
    piState = &rgiState[2];
    piState[-2] = 55 - 55;
    piState[-1] = 55 - 24;
    piState[0] = ((int) time(NULL))&((1 << 30)- 1);
    piState[1] = 1;
    for(iState = 2; iState < 55; iState++)
    {
        piState[istate] = (piState[iState - 1] + piState[iState - 2])
        & ((1 << 30)- 1);
    }
    return;
}




yea so thats it! later

-FA





"Only two things are infinite in this world. The universe, and human stupidity. And I'm not sure about the universe." - Albert Einstien
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
Game programming. Magxtopher BOOK: Beginning JavaScript 3rd Ed. ISBN: 978-0-470-05151-1 3 September 11th, 2008 09:49 AM
Pong Game Help -XM- BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6 4 June 20th, 2007 02:23 PM
Old game review guti Need help with your homework? 0 March 20th, 2007 11:28 AM
text game 132591 C++ Programming 18 December 15th, 2006 09:12 AM
STRATEGIE - GAME! WarKrife C++ Programming 1 August 21st, 2003 08:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.