C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-10-2009, 01:29 PM   #1
Registered User
 
Join Date: Mar 2009
Posts: 16
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




Code:
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;

int Dice (int dice1, int dice2)
{
time_t seconds;
time(&seconds);
srand((unsigned int) seconds);
dice1 = rand() % (5 + 1)+1;
dice2 = rand() % (5 + 1)+1;
return (dice1, dice2);
}

int rules()
{ 
    system("cls");
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";
system("Pause");
int main ();
}

int game()
{ 
    int times;
    system("cls");
    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)
   {rules();}
   else
   {game();}
int dice1;
int dice2 ;   
cout << "First Dice = " << dice1 <<  endl;
cout << "Second Dice = " << dice2 << endl;

system("pause");

}
CaliJoe is offline   Reply With Quote
Old 03-10-2009, 01:30 PM   #2
and the Hat of Guessing
 
tabstop's Avatar
 
Join Date: Nov 2007
Posts: 8,740
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.
tabstop is offline   Reply With Quote
Old 03-10-2009, 04:35 PM   #3
Registered User
 
Join Date: Jan 2005
Posts: 7,137
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.
Daved is offline   Reply With Quote
Reply

Tags
beginner, dice, game, random

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Dice game: How to handle 2 players and separate totals? crazychile C Programming 7 10-20-2008 12:01 AM
Need book to program game into multiplayer... edomingox Game Programming 3 10-02-2008 09:26 AM
Try my game LuckY A Brief History of Cprogramming.com 14 09-15-2004 11:58 AM
how do the game engine and the api interact? Shadow12345 Game Programming 7 06-05-2002 10:06 PM
My Maze Game --- A Few Questions TechWins Game Programming 18 04-24-2002 11:00 PM


All times are GMT -6. The time now is 12:10 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22