Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,399 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,226 people online right now. Registration is fast and FREE... Join Now!




i made the changes and still dont work

 
Reply to this topicStart new topic

i made the changes and still dont work, yatzee dice in c++

dinisrainman
14 Feb, 2008 - 05:36 PM
Post #1

New D.I.C Head
*

Joined: 10 Feb, 2008
Posts: 24

[#include <iostream>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;

int main()
{
char option = 'y';
int humanTotal = 0;
int computerTotal = 0;
int total = 0;
int die1 = 0 ;
int die2 = 0 ;
int die3 = 0 ;
int yatzeeRoll(int);
//initializes the number
srand(time(0));

int randomNumber = rand();

die1 = 1 +(randomNumber) % (6 - 1 + 1);
die2 = 1 +(randomNumber) % (6 - 1 + 1);
die3 = 1 +(randomNumber) % (6 - 1 + 1);

cout << "Welcome to Yatzee!" "Press enter to throw your dice:";
cin.get();

while (option == 'y')
{
cout << "you rolled a :" << die1 << " and " << die2 << endl;

// human and computers score
humanTotal = yatzeeRoll(total);
computerTotal = yatzeeRoll(total);


if (humanTotal == 12)
{
cout << " You total Score is" << humanTotal << endl;
cout << "Yatzee." "Congratulations you win" << endl;
}
else if ( humanTotal > 12 )
{

cout << "You Lose!" " Roll again?";
}
else if ( humanTotal < 12)
{
cout << "Do you want to try another roll(y/n)?:";
cin >> option;
}
else if ( computerTotal == 12 )
{
cout << " The Computer Wins ";
}
else if ( computerTotal > 12 )
{
cout << "Computer loses!";
}
else if ( computerTotal < 12 )
{
cout << "Give chance to computer to try again:";
cin >> option;
}
else if ( humanTotal > computerTotal )
{
cout << "Human wins!";
}
else
{
cout << "Computer wins!";
}
system ("pause");
}return 0;
}

int yatzeeRoll(int total )
{

// calculate numbers
int randomNumber = rand();

int die1 = 1 +(randomNumber) % (6 - 1 + 1);
int die2 = 1 +(randomNumber) % (6 - 1 + 1);
int die3 = 1 +(randomNumber) % (6 - 1 + 1);

total = die1 + die2;

if ( total != 12 )
{
total += die3;
}

return total;
}]

i have made all the changes but still im getting the same result.
this what i get
[the dice rolled 3 and 3]
[press any key to continue]

This how it should look like.

[Welcome to Yatzee! Press Enter to throw your dice:]
[The diced rolled 6 and 6]
Yatzee! Your total is 12.
[You win. Congratulations!]

[Here is a second use-case:]

[Welcome to Yatzee! Press Enter to throw your dice:]
[The diced rolled 5 and 4]
[Your total is 9]
[Do you want to throw one more die (y or n) ? y]
[The die rolled: 5. Your total is 14]
[You are busted!]

[The computer wins. Sorry!]
[Here is a third use-case:]
Welcome to Yatzee! Press Enter to throw your dice:
The diced rolled 3 and 5
Your total is 8
Do you want to throw one more die (y or n) ? y
The die rolled: 2. Your total is 10
It is the computer's turn to throw the dice.
The diced rolled 5 and 3. The computer's total is 8
The computer rolls again.
The dice rolled 5. The computer's total is 13.
The computer is busted!
You win. Congratulations!]
User is offlineProfile CardPM
+Quote Post

GWatt
RE: I Made The Changes And Still Dont Work
14 Feb, 2008 - 05:48 PM
Post #2

human inside
Group Icon

Joined: 1 Dec, 2005
Posts: 2,356



Thanked: 31 times
Dream Kudos: 500
My Contributions
code.gif
User is offlineProfile CardPM
+Quote Post

Nykc
RE: I Made The Changes And Still Dont Work
14 Feb, 2008 - 06:28 PM
Post #3

That Just Happened!
Group Icon

Joined: 14 Sep, 2007
Posts: 4,455



Thanked: 18 times
Dream Kudos: 275
My Contributions
This is a double post. Atleast the other one is between code.gif tags.
User is online!Profile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/7/09 10:15AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month