Question

can someone help me fix my jeopardy game #include<iostream> #include<stdlib.h> using namespace std; int rollDie() {...

can someone help me fix my jeopardy game

#include<iostream>
#include<stdlib.h>
using namespace std;


int rollDie()
{
return (rand() % 6+1);
}

void askYoNs(){
cout<<"Do you want to roll a dice (Y/N)?:"<<endl;
}

void printScores(int turnTotal,int humanTotal,int compTotal){

int player;
int human;
if(player==human){
cout<<"Your turn total is "<<turnTotal<<endl;
}
else{
cout<<"computer turn total is "<<turnTotal<<endl;
}
cout<<"computer: "<<compTotal<<endl;
cout<<"human: "<<humanTotal<<endl;
cout<<endl;
}
int human;
int changePlayer(int player){
if(player==human)
return 1;
return human;
}
int process(int& turnTotal,int roll,int curr_player,int& humanTotal,int& computerTotal){
if(roll==2 || roll==5){
curr_player=changePlayer(curr_player);
turnTotal=0;
printScores(turnTotal,humanTotal,computerTotal);
}
else if(roll==4){
turnTotal=15;
///switch player
if(curr_player==human)
humanTotal+=turnTotal;
else
computerTotal+=turnTotal;
curr_player=changePlayer(curr_player);
turnTotal=0;
printScores(turnTotal,humanTotal,computerTotal);
}
else{ ///roll = 1 3 6
turnTotal+=roll;
cout<<"Your turn total is "<<turnTotal<<endl;
}
///if computer turnTotal becomes >=10
///then switch player
if(curr_player!=human){
computerTotal+=turnTotal;
curr_player=changePlayer(curr_player);
turnTotal=0;
printScores(turnTotal,humanTotal,computerTotal);
}
return curr_player;
}
void game(){
int player=human;
int humanTotal=0;
int computerTotal=0;
int turnTotal=0;

if (turnTotal==0){
cout<<"Welcome to Jeopardy Dice!"<<endl;
}
while(humanTotal<=80 && computerTotal<=80){
int roll=0;
if(player==human){
cout<<endl;
cout<<"It is now human's turn "<<endl;
  
cout<<endl;
char YoN;
askYoNs();
cin>>YoN;
roll=rollDie();
cout<<"You rolled a "<<roll<<endl;
player=process(turnTotal,roll,player,humanTotal,computerTotal);
if(YoN=='Y'){
humanTotal+=turnTotal;
player=1; ///switch player to Computer
printScores(turnTotal,humanTotal,computerTotal);
turnTotal=0;
continue;
}
}   
else
cout<<endl;
cout<<"It is now computer's turn"<<endl;
cout<<endl;
roll=rollDie();
cout<<"Computer rolled a "<<roll<<endl;
player=process(turnTotal,roll,player,humanTotal,computerTotal);
}///while ends here

///check who is winner
if(humanTotal>=80){
cout<<"Congratulations! human won this round of Jeopardy Dice!"<<endl;
}
else{
cout<<"Congratulations! computer won this round of Jeopardy Dice!"<<endl;
}
}
int main()
{
game();
return 0;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go this code and let me know if u need any changes in this.Thank You
_________________

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

int rollDice();
int humanTurn(int turn);
int computerTurn(int turn);
void game();
int main ()
{
game();
return 0;
}

int rollDice()
{
return rand()%6+1;
}

// simulate human's turn

int humanTurn(int turn)

{
char rolltheDice='y';
char rollAgain='y';
int turnTotal=0;
int dice_value;
cout << " It is now human's turn" << endl<< endl;
while(true)
{

dice_value = rollDice();
cout<<"You rolled a "<<dice_value<<endl;
switch(dice_value)
{
case 2:
case 5:
turnTotal=0;
turn = 0;
cout<<"Your turn total is "<<turnTotal<<endl;
return 0;
case 4:
turnTotal=15;
turn =0;
cout<<"Your turn total is "<<turnTotal<<endl;
return turnTotal;
break;
case 1:
case 3:
case 6:
turnTotal += dice_value;
break;

}
cout<<"Player turn total is "<<turnTotal<<endl;
cout << "Do you want to roll again (Y/N)? ";
cin >> rollAgain;
if(rollAgain == 'n' || rollAgain == 'N')
{
break;
}

}
turn = 0;
return turnTotal;

}

// simulate computer's turn
int computerTurn(int turn)
{
int compturnTotal = 0;
int dice_value;
cout << " It is now computer's turn"<<endl;
char rollAgain = 'y';
while(compturnTotal < 10 && rollAgain =='y')
{
dice_value = rollDice();
cout<<" Die roll : "<<dice_value<<endl;
switch(dice_value)
{
case 2:
case 5:
compturnTotal=0;
rollAgain='n';
break;
case 4:
compturnTotal=15;
rollAgain='n';
break;
case 1:
case 3:
case 6:
compturnTotal += dice_value;
break;
}
cout<<"Computer turn total is "<<compturnTotal<<endl;

}
turn = 1;
return compturnTotal;
}

void game()
{
   cout << "Welcome to Jeopardy Dice!" << endl << endl;
  
int turn = 1;
int compTotal = 0;
int humanTotal = 0;

while(compTotal < 80 && humanTotal <80)
{
if(turn == 1)
{
humanTotal += humanTurn(turn);
turn=2;
}
else
{
compTotal += computerTurn(turn);
turn=1;
cout<< " Computer: "<< compTotal << " Human: "<< humanTotal << endl;
}

}
if(humanTotal >=80)
{
cout<<"Human wins"<<endl;
}

else
{
cout<<"Computer wins"<<endl;
}

}

________________________

Output:


_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
can someone help me fix my jeopardy game #include<iostream> #include<stdlib.h> using namespace std; int rollDie() {...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • can someone help me fix my jeopardy dice game I am having a hard time figuring...

    can someone help me fix my jeopardy dice game I am having a hard time figuring out what i am doing wrong #include #include using namespace std; //this function makes a number between 1 and 6 come out just like a dice int rollDie() { return (rand() % 6+1); } //this function asks the user with a printed statement if they want to roll the dice and gives instructions for yes and no (y/n) void askYoNs(){ cout<<"Do you want to...

  • This is for C++ #include <random> #include <iostream> #include <ctime> using namespace std; /* In the...

    This is for C++ #include <random> #include <iostream> #include <ctime> using namespace std; /* In the game of craps, a shooter rolls 2 dice and adds the dots on the upper most faces of the dice. 7 or 11 on the first roll wins, 2, 3, or 12 on the first roll loses, andthing else is call the point and the player rolls again The following program fragment uses 1-way if statements simulate the 1st roll of the dice. Replace...

  • Game of Craps C++ #include <iostream> using namespace std; void roll (int *); // using pointer...

    Game of Craps C++ #include <iostream> using namespace std; void roll (int *); // using pointer to catch the random variable value of two dicerolls at one time . //these global variable with static variable win use to operate the working of code . //static win, account because two times input given by user to add the diceroll with win number and //account (means balance of user) . static int account = 100; static int win = 0; int bet...

  • The Code is C++ // tic tac toe game #include <iostream> using namespace std; const int SIZE = 9; int check(char *); void displayBoard(char *); void initBoard(char *); int main() {    char board[...

    The Code is C++ // tic tac toe game #include <iostream> using namespace std; const int SIZE = 9; int check(char *); void displayBoard(char *); void initBoard(char *); int main() {    char board[SIZE];    int player, choice, win, count;    char mark;    count = 0; // number of boxes marked till now    initBoard(board);       // start the game    player = 1; // default player    mark = 'X'; // default mark    do {        displayBoard(board);        cout << "Player " << player << "(" << mark...

  • please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName();...

    please help me fix the error in here #include<iostream> #include <string> using namespace std; string getStudentName(); double getNumberExams(); double getScoresAndCalculateTotal(double E); double calculateAverage(double n, double t); char determineLetterGrade(); void displayAverageGrade(); int main() { string StudentName; double NumberExam, Average, ScoresAndCalculateTotal; char LetterGrade; StudentName = getStudentName(); NumberExam = getNumberExams(); ScoresAndCalculateTotal= getScoresAndCalculateTotal(NumberExam); Average = calculateAverage(NumberExam, ScoresAndCalculateTotal); return 0; } string getStudentName() { string StudentName; cout << "\n\nEnter Student Name:"; getline(cin, StudentName); return StudentName; } double getNumberExams() { double NumberExam; cout << "\n\n Enter...

  • can someone help me with this C++ problem write your game() function and 3+ functions that...

    can someone help me with this C++ problem write your game() function and 3+ functions that simulate the game of Jeopardy Dice according to the following game mechanics and specifications. Game Mechanics There are two players: the user and the computer, who alternate turns until one of them reaches 80 points or higher. The user is always the first player and starts the game. If any player reaches 80 points or more at the end of their turn, the game...

  • Find and fix errors #include <iostream> #include <cstdlib> #include <ctime> using namespace std; const int MIN...

    Find and fix errors #include <iostream> #include <cstdlib> #include <ctime> using namespace std; const int MIN = 1; const int MAX = 10; int getRandom(int low, int high); int main() {    int random_num = 0; int player_num; int tries; int seed = static_cast<int>(time(0)); bool guessed = false;    srand(seed); // call the getRandom function below       tries = 4; while ( tries > 0 && !guessed ) { cout << "Enter a number within the range 1 to...

  • #include "stdafx.h" #include <iostream> using namespace std; class dateType {    private:        int dmonth;...

    #include "stdafx.h" #include <iostream> using namespace std; class dateType {    private:        int dmonth;        int dday;        int dyear;       public:       void setdate (int month, int day, int year);    int getday()const;    int getmonth()const;    int getyear()const;    int printdate()const;    bool isleapyear(int year);    dateType (int month=0, int day=0, int year=0); }; void dateType::setdate(int month, int day, int year) {    int numofdays;    if (year<=2008)    {    dyear=year;...

  • Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout...

    Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout << "Enter an integer cin >> number; if (number > B) cout << You entered a positive integer: " << number << endl; else if (number (8) cout<<"You entered a negative integer: " << number << endl; cout << "You entered e." << endl; cout << "This line is always printed." return 0;

  • #include <iostream> #include <chrono> using namespace std; double improvedPow(double x, int y) { // To be...

    #include <iostream> #include <chrono> using namespace std; double improvedPow(double x, int y) { // To be implemented by you } int main() { cout << "To calculate x^y ..." << endl; double x; int y; cout << "Please enter x: "; cin >> x; cout << "Please enter y: "; cin >> y; if(x == 0) { if (y > 0) cout << 0 << endl; else cout << "x^y is not defined" <<endl; } else { cout << improvedPow(x,y)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT