View Single Post
  #1 (permalink)  
Old February 1st, 2006, 11:36 PM
FAdirtbmx FAdirtbmx is offline
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