so i wrote this code that basically simulates the playing of craps.
the code worked fine but i have to write it using classes. Since ive never programed using classes i dont know what im doing wrong. the issue im having is that there is no output showing. I get no compiler errors or debugging errors.
Any help would be greatly appreciated. Below i have included all my classes and header files.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
//main.cpp
#include <iostream>
#include <ctime> // for time()
#include <cstdlib>
#include "roll.h"
#include "game.h"
usingnamespace std;
int main ()
{
game mygame;
mygame.play_game(0);
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
//roll.h
#ifndef ROLL_H
#define ROLL_H
class roll
{
public:
roll(int, int);
roll();
int die1;
int die2;
int toss;
~roll();
};
#endif // ROLL_H
//roll.h
#ifndef ROLL_H
#define ROLL_H
class roll
{
public:
roll(int, int);
roll();
int die1;
int die2;
int toss;
int throw_dice;
~roll();
};
#endif // ROLL_H
Also would i put the srand in the game.h file or the roll.h file?
ah now it seems to output.
however....
its giving me a very large negative number, and the same number
i think it might be because i dont have my srand(time(0)) set up in my classes, any hints on where it would go?
//main.cpp
#include <iostream>
#include <ctime> // for time()
#include <cstdlib>
#include "roll.h"
#include "game.h"
usingnamespace std;
int main ()
{
game mygame;
mygame.play_game(0);
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
//roll.h
#ifndef ROLL_H
#define ROLL_H
class roll
{
public:
roll(int, int);
roll();
int die1;
int die2;
int toss;
void throw_dice();
int srand();
~roll();
};
#endif // ROLL_H