|
[#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!]
|