Question

I need help figuring out how to code this in C++ in Visual Studio. Problem Statement:...

I need help figuring out how to code this in C++ in Visual Studio.

Problem Statement: Open the rule document for the game LCR Rules Dice Game.

Develop the code, use commenting to describe your code and practice debugging if you run into errors. Submit source code.

Use the document to write rules for the user on how to play the game in a text file. Then, using the information from the resource articles, create a program that will read in the text file and display it out to the user.

Text File:

Develop a program that follows the rules of Left Center Right (LCR) as described. On program start-up, it shall display the rules to the user as read from a text file submitted with the program. The user can then set up the game by entering the number of players. Any number below three shall ask the user to add more players. Once gameplay has started based on the game rules, there are a few main pieces to address. Rolling the die should be performed by randomly generating the side of the die displayed for each of the three using a random number generator. For this game, if the generated number is 1, that will be L. Additionally, 2 is R, 3 is C, and 4–6 are dots that can be represented with the asterisk symbol *. Be sure to check the current player’s number of chips before rolling. After each player’s roll, calculate the number of chips for players based on the actions dictated by the dice. Continue playing until only one player has chips. Display a message to the game winner.

Left Center Right (LCR) is a multiplayer dice game with a minimum of three players, but no upper limit on the number of participants. The goal is to win all of the chips.

The Dice ● There are three dice rolled each turn. Each die has the letters L, C, and R on it along with dots on the remaining three sides. These dice determine where the player’s chips will go.

● For each L, the player must pass one chip to the player sitting to the left.

● For each R, the player must pass one chip to the player sitting to the right.

● For each C, the player must place one chip into the center pot and those chips are now out of play.

● Dots are neutral and require no action to be taken for that die.

The Chips

● Each player will start with three chips.

● If a player only has one chip, he/she rolls only one die. If a player has two chips left, he/she rolls two dice. Once a player is out of chips, he/she is still in the game (as he/she may get chips passed to him/her), but passes the dice to the next player. Winning the Game

● The winner is the last player with chips

My current code:

// Header
#include <iostream>
#include <fstream>

// Namespace
using namespace std;

// Main Function
int main()
{
   string st;
   ifstream file("lcrRules.txt"); // Read file
   cout << "The rules are as follows : " << endl;

   if (file.is_open())
   {
       while (getline(file, st)) // While open
       {
           cout << st << ' ';
       }
       file.close(); // closing file
   }
   else // Else print string
   {
       cout << "Cannot open file";
   }
   return 0;
}

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

FOR READING AND DISPLAYING FROM A FILE, I AM USING fstream INSTEAD OF ifstream.

FIRST CREATE A .txt FILE WITH THE NAME "IcrRules.txt" AND SAVE THIS FILE IN THE FOLDER IN WHICH YOUR PROGRAM CODE FILE IS SAVED.

THE CONTENT OF THIS FILE SHOULD BE THE RULES DESCRIBED IN THE QUESTION AS FOLLOWS :-

THIS IS LOCATION OF IcrRules.txt FILE AND PROGRAM CODE FILE IN MY PC.  

IF YOU ARE NOT SAVING IT IN THE SAME FOLDER AS CODE FILE, THEN THE OUTPUT YOU GET IS

THE PROGRAM CODE FOR THE QUESTION IN C++ IS AS FOLLOWS :-

// Header
#include <iostream>
#include <fstream>

// Namespace
using namespace std;

// Main Function
int main()
{
   // fstream class object to read from the file
   fstream file;
  
   // string variable

   string filename;
  
   cout << "The rules are as follows : " << endl;
  
   // name of the file
   filename = "IcrRules.txt";
  
   // opening file
   file.open(filename.c_str());
  
   if (file.is_open())
   {
        // While open read from file
   while (getline(file, filename))
       {
           // print the line readed from the file
   cout << filename <<endl;
   }
  
   // closing file
   file.close();
   }
   else // Else print string
   {
   cout << "Cannot open file";
   }
   return 0;
}

THE OUTPUT OF THE ABOVE CODE IS AS FOLLOWS :-

HOPE YOU UNDERSTAND WHAT TO DO.

Add a comment
Know the answer?
Add Answer to:
I need help figuring out how to code this in C++ in Visual Studio. Problem Statement:...
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
  • I need some help creating C++ Left, Center, Right (LCR) dice game Pseudocode. Address the following : A. Analyze the giv...

    I need some help creating C++ Left, Center, Right (LCR) dice game Pseudocode. Address the following : A. Analyze the given problem statement. B. Break the problem down into distinct steps of pseudocode that will solve the problem. C. Create variables to track the various elements in the pseudocode. D. If applicable, determine any breakdown of pseudocode into functions and/or classes. E. Use natural language to work through the problems. Using three special dice and player pieces called chips. In...

  • C# Code: Write the code that simulates the gambling game of craps. To play the game,...

    C# Code: Write the code that simulates the gambling game of craps. To play the game, a player rolls a pair of dice (2 die). After the dice come to rest, the sum of the faces of the 2 die is calculated. If the sum is 7 or 11 on the first throw, the player wins and the game is over. If the sum is 2, 3, or 12 on the first throw, the player loses and the game is...

  • ********C++******** Develop the code to solve the problem statement below. Follow these style guidelines as you...

    ********C++******** Develop the code to solve the problem statement below. Follow these style guidelines as you develop the code. Use commenting to describe your code, and practice debugging if you run into errors. Submit your final source code. Problem Statement: Open the rule document for the game you selected for your final project: LCR Rules Farkle Rules Liar's Dice Rules Use the document to write rules for the user on how to play the game in a text file. Then,...

  • python code( using functions please)! Rules of the game: - This game requires a dice. The...

    python code( using functions please)! Rules of the game: - This game requires a dice. The goal of the game is to collect the correct number of coins to create a dollar. Players take coins based on a roll of the dice. The numbers on the dice correlate to the coin values as follows:  1—penny  2—nickel  3—dime  4—quarter  5— ( pick a random card from 1 to 4): o 1 = penny o 2 =...

  • 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...

  • Need done in C++ Can not get my code to properly display output. Instructions below. The...

    Need done in C++ Can not get my code to properly display output. Instructions below. The code compiles but output is very off. Write a program that scores the following data about a soccer player in a structure:            Player’s Name            Player’s Number            Points Scored by Player      The program should keep an array of 12 of these structures. Each element is for a different player on a team. When the program runs, it should ask the user...

  • The Rules of Pig Pig is a folk jeopardy dice game with simple rules: Two players...

    The Rules of Pig Pig is a folk jeopardy dice game with simple rules: Two players race to reach 100 points. Each turn, a player repeatedly rolls a die until either a 1 (”pig”) is rolled or the player holds and scores the sum of the rolls (i.e. the turn total). At any time during a player’s turn, the player is faced with two decisions: roll If the player rolls a 1: the player scores nothing and it becomes the...

  • The game of Pig is a simple two-player dice game in which the first player to...

    The game of Pig is a simple two-player dice game in which the first player to reach 100 or more points wins. Players take turns. On each turn, a player rolls a six-sided die: If the player rolls a 1, then the player gets no new points and it becomes the other player’s turn. If the player rolls 2 through 6, then he or she can either ROLL AGAIN or HOLD:      At this point, the sum of all rolls...

  • I need help solving this in c++ using visual Studio. For this assignment, you will be filling in missing pieces of code within a program, follow the comments in the code. These comments will describe...

    I need help solving this in c++ using visual Studio. For this assignment, you will be filling in missing pieces of code within a program, follow the comments in the code. These comments will describe the missing portion. As you write in your code, be sure to use appropriate comments to describe your work. After you have finished, test the code by compiling it and running the program, then turn in your finished source code. // TicTacToe.cpp: Follow along with...

  • Please, I need help with program c++. This is a chutes and ladders program. The code...

    Please, I need help with program c++. This is a chutes and ladders program. The code must be a novel code to the specifications of the problem statement. Thank you very much. Assignment Overview This program will implement a variation of the game “chutes and ladders” or “snakes and ladders:” https://en.wikipedia.org/wiki/Snakes_and_Ladders#Gameplay. Just like in the original game, landing on certain squares will jump the player ahead or behind. In this case, you are trying to reach to bottom of the...

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