Thread: Help With Dice Game

  1. #1
    Registered User
    Join Date
    Mar 2009

    Help With Dice Game

    Hi, i was working on this for my class and i can't seem to get this to work. I am not quite done yet but i have a few problems. After my rules and game function, i would like it to return to the home screen (call the main) again but it dosen't seem to do that. When i click 1 for the rules it displays the rules then plays the game instead of returing home. Then i the random number dice are not number between 1 to 6. Why ? Thanks

    #include <iostream>
    #include <cstdlib>
    #include <time.h>
    using namespace std;
    int Dice (int dice1, int dice2)
    time_t seconds;
    srand((unsigned int) seconds);
    dice1 = rand() % (5 + 1)+1;
    dice2 = rand() % (5 + 1)+1;
    return (dice1, dice2);
    int rules()
    cout << " The Rules Are Quite Simple. We Roll Two Dice.\n -If Even, Player 1 Gets a Point\n If Odd, Player 2 Gets a Point\n";
    int main ();
    int game()
        int times;
        cout << "How Many Times Would You Like to Roll?";
        cin >> times;
        int Dice (int dice1, int dice2);
        int main ();
    int main()
        int key;
    cout << "Menu\n Press 1 for Rules\n Press Any Key to Play\n"  ;
    cin >> key;
    if (key==1)
    int dice1;
    int dice2 ;   
    cout << "First Dice = " << dice1 <<  endl;
    cout << "Second Dice = " << dice2 << endl;

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Calling main is neither necessary nor desirable (it might even be impossible in C++, I don't remember). You just need to put a loop inside main, is all.

  3. #3
    Registered User
    Join Date
    Jan 2005
    You should also only be calling srand once in a program, so putting it inside your Dice function is a bad idea. Put the call to srand at the start of main so it only gets called once.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-08-2010, 12:08 AM
  2. Dice game: How to handle 2 players and separate totals?
    By crazychile in forum C Programming
    Replies: 7
    Last Post: 10-20-2008, 12:01 AM
  3. Need book to program game into multiplayer...
    By edomingox in forum Game Programming
    Replies: 3
    Last Post: 10-02-2008, 09:26 AM
  4. Try my game
    By LuckY in forum A Brief History of
    Replies: 14
    Last Post: 09-15-2004, 11:58 AM
  5. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM

Tags for this Thread