#include <iostream>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <time.h>
using namespace std;
using std::cout;
using std::cin;
using std::endl;
// variables in the game.
int player1turn (int) ;
int player2turn (int) ;
int diceroll ();
const int winscore= 100;
int main ()
{
srand (time (NULL));
int player1score = 0 ;
int player2score = 0 ;
do
{
player1score = player1score + player1turn( player1score );
cout << " Player 1 total score is " << player1score << endl;
if ( player1score >= winscore )
{
cout << "Player 1 has won !! " ;
return 0;
}
player2score = player2score + player2turn(player2score) ;
cout << "PLayer 2 total score is " << player2score << endl;
if ( player2score >= winscore)
{
cout<< "PLayer 2 has won !! ";
return 0;
}
}
while ( player1score < winscore && player2score < winscore);
}
//The code for the game- allows players to roll the dice and gives them the option to hold or roll again
//Also holds their score
int player1turn (int player1score)
{
int thisscore= 0 ;
int roll= 0;
char rOh;
do
{
roll = diceroll () ;
if (roll == 1 )
{
cout << "You have rolled a 1. It's the end of your turn " << endl;
return 0;
}
thisscore = thisscore + roll ;
cout << "You have rolled a " << roll << " . Your score so far is " << thisscore << endl;
do
{
cout << "Do you want to roll again (r) or hold (h) ? " ;
cin >> rOh ;
}
while (rOh == 'r' );
if ( rOh == 'h')
return player1score;
}
int player2turn (int player2score)
{
int thisscore= 0 ;
int roll= 0;
char rOh;
do
{
roll = diceroll () ;
if (roll == 1 )
{
cout << "You have rolled a 1. It's the end of your turn " << endl;
return 0;
}
thisscore = thisscore + roll ;
cout << "You have rolled a " << roll << " . Your score so far is " << thisscore << endl;
do
{
cout << "Do you want to roll again (r) or hold (h) ? " ;
cin >> rOh ;
while (rOh == 'r' );
if ( rOh == 'h')
return thisscore;
}
//Random dice generator
int diceroll ()
{
int roll ;
roll = ( rand () % 6 ) +1 ;
}
my errors are :
1>c:\users\victor\documents\visual studio 2010\projects\game1\game1\game1.cpp(27): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>c:\users\victor\documents\visual studio 2010\projects\game1\game1\game1.cpp(94): error C2062: type 'int' unexpected
1>c:\users\victor\documents\visual studio 2010\projects\game1\game1\game1.cpp(95): error C2143: syntax error : missing ';' before '{'
1>c:\users\victor\documents\visual studio 2010\projects\game1\game1\game1.cpp(126): error C2062: type 'int' unexpected
1>c:\users\victor\documents\visual studio 2010\projects\game1\game1\game1.cpp(128): error C2143: syntax error : missing ';' before '{'
1>c:\users\victor\documents\visual studio 2010\projects\game1\game1\game1.cpp(133): fatal error C1075: end of file found before the left brace '{' at 'c:\users\victor\documents\visual studio 2010\projects\game1\game1\game1.cpp(102)' was matched
not sure how to fix them
MOD EDIT: Added code tags. When posting code...USE CODE TAGS!!!

New Topic/Question
Reply



MultiQuote





|