any one have any suggestions why my code won't work?

#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;

int intro(int &num_games);
int random();

int main(void)
{
    int seed(0), num_games(0);
    int point, point2(1);
    int a(0), b(0), c(0), d(0);

    cout<<"Lexi Barlow and Alex Puffer    craps.cpp"<<endl;

    intro(num_games);

    cout<<"\nEnter a random seed number: "<<endl;
    cin>>seed;
    srand(seed);

    while(num_games>0)
    {
        cout<<"\nYou have "<<num_games<<" games left."<<endl;
        num_games--;
        cout<<"Roll the die"<<endl;
        system("pause");
        a=random();
        b=random();
        point=a+b;
        cout<<"\nYou rolled "<<a<<"+"<<b<<"="<<point<<"."<<endl;
        
        if(point==7)
        {cout<<"You win!";}
        else if(point==11)
        {cout<<"You win!";}
        else if(point==2)
        {cout<<"You lose.";}
        else if(point==3)
        {cout<<"You lose.";}
        else if(point==12)
        {cout<<"You lose.";}
        else
        {
            while((point2!=7)||(point2!=point))
                {
                cout<<"You roll again\n";
                c=random();
                d=random();
                point2=c+d;
                cout<<"\nYou rolled "<<c<<"+"<<d<<"="<<point2<<"."<<endl;
                if (point2==7)
                {cout<<"You lost";}
                else if (point2==point)
                {cout<<"You won";}
                }
        }
        }
       
    
system("pause");
return(0);
}

int intro(int &num_games)
{
    cout<<"\nOur program simulates a game of craps. "<<endl;
    cout<<"Random numbers will be generated to simulate rolling dice. "<<endl;
    cout<<"You will need to input a random seed number and the number "<<endl;
    cout<<"of games you would like to play. Enjoy!"<<endl;

    cout<<"How many games would you like to play? "<<endl;
    cin>>num_games;
    return(num_games);
}

int random()
{ 
    return 1+ rand()%6;
}

Recommended Answers

All 3 Replies

Care to supply some details? Or are we supposed to guess?

No idea why it doesn't work. What does it do that it is not supposed to do? Or what doesn't it do that it should?

I ran it and it worked just fine. Just a tip though, try spacing out some of your code. It's sorta hard to read.

like change this:

cout<<"CRAPS IS A FUNNY NAME"<<endl;

to this:

cout << "CRAPS IS A FUNNY GAME" << endl;

I'm just saying.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.