Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Program I have my good.txt and bad.txt file as well as the dice file. I just

ID: 3602639 • Letter: C

Question

C++ Program

I have my good.txt and bad.txt file as well as the dice file. I just need help with setting the program up with arrays and loops. So far I have spent 20+ hours on trying to figure this simple program out so if figured it was time to ask the professionals, thank you in advance for taking the time to help me with this.

You are writing a game where your players navigate through an imaginary world (board) using an imaginary dice.   Your imaginary world has good things and bad things in it. Each player begins the game with zero money in their account and on board space zero. Each player has a turn where all they do is roll a dice. When a player lands on a space, either good or bad is selected randomly. If good, then something good happens to the player, a smiley face is printed, and money is added to their account. If bad, then something bad happens to the player, a frown face is printed, and money is subtracted from their account. The game ends when a player lands on or goes past the ending space on the board.

CONSTANT VARIABLES

Maximum Number of Players possible: 20

Number of Spaces on Board: 25

OVERALL PROGRAM

You will have three arrays:   o        names – will hold the names of players playing the game. Example: names[0] could hold April Crockett and names[1] could hold Jason Crockett if April & Jason are currently playing the game.

boardSpace – will hold the current location (space) of players playing the game. Example: boardSpace[0] could hold 15 and boardSpace[2] could hold 6 if April was currently at space 15 on the board and Jason was currently at space 6 on the board.

money –will hold how much money each player has playing the game. Example: money[0] could hold 50000 and money[1] could hold -4000 if April currently had $50,000 and Jason had -$4,000. (yes – people can have a negative balance in the game!)

You will allow your players to play the game as many times as they want

You can name your imaginary land whatever you want.

You will create two text files – bad.txt and good.txt. There is more details on this later in this document.

PROGRAM SPECIFICATIONS / FLOW

Print out the name of your imaginary land/game. (Mine is called CROCKETTLAND – but you can name yours whatever you want)

Ask user how many players are playing and validate that they didn’t enter more than the maximum number of players – and that it is more then zero.

Set up your arrays for the start of the game! Set each element of names array to an empty string, each element of boardSpace array to zero, and each element of money array to 0.0.

Get each player’s name and place their name in each element of the names array. Notice when the player’s names are printed out in the samle output. Your program should print out the player’s names in the same way.

Create a loop that will iterate until one of the players has reached the last space on the board.

Create another loop to iterate through each of the players for each turn. For each player’s turn, you will:

Print out the player’s name and tell them to press enter to roll die.

Randomly generate a number between 1 & 6 (for the dice roll)

Print a cool picture of the dice that was rolled

code given to you in dice.cpp

Add the randomly generated number to the position in the boardSpace array that corresponds to the current player.

If they have reached the end of the board, then print out that they finished the board and then print the results (explained in its own section below).

If they have not reached the board, then…

Print out their current board space and then display what happens on the space (explained in its own section below).  

Randomly generate a number between $1 and $100,000 for the money amount.

If a good thing happened, then add the random money amount to the money array for the current player and print out how much was added. Otherwise, if a bad thing happened, then subtract the money from the money array for the current player and print out how much was subtracted.

Print out how much money the player has in his or her account.

After a player reached the ending space on the board and the results have all been printed, then ask the user if they want to play again.

Display what happens on the space – good or bad. There are two text files containing the text of what happens. You will have to create each text file by opening notepad or another editor and manually typing them. The good.txt text file should contain 20 good things that can happen to the player. The bad.txt text file should contain 20 bad things that can happen to the player.

First, randomly generate either a 1 or 2. 1 will represent something good happening and 2 will represent something bad happening.

If good, then… o Open the good.txt file

Print out a big smiley face (doesn’t have to look exactly like mine but it has to be happy) o          Print the word “GREAT! “ (or something similar)

If bad, then… o    Open the bad.txt file

Print out a big frowny face (doesn’t have to look exactly like mine but it has to be sad) o Print the word “OH NO! “ (or something similar)

Then randomly generate a number between 1 & 20.

Use a for loop that iterates the number of times that was randomly generated in the step above. o           In the for loop, read in a line from the file using getline.

After the for loop, print out the line from the file

This code should execute when one of the players reached the last space on the board. It will display the results of the game – who reached the end of the board and also who ended up with the most money.

Use a for loop to iterate through the boardSpace array and find the player who reached the highest boardSpace. Capture this player’s name.

Print out the player who had the highest board space.

Use a for loop to iterate through the money array and find the player who had the most money at the end of the game. Capture this player’s name.

Print out the player who had the most money.

               

OUTPUT – YOUR OUTPUT SHOULD LOOK VERY SIMILAR TO MINE!!

SAMPLE TEXT FILE – good.txt

(YOU HAVE TO WRITE YOUR OWN GOOD ACTIONS!)

SAMPLE TEXT FILE – bad.txt    

(YOU HAVE TO WRITE YOUR OWN BAD ACTIONS)

               

SAMPLE OUTPUT OF PROGRAM RUNNING

YOU ARE PLAYING CROCKETTLAND! How many players? 2 PLAYER 1, WHAT IS YOUR NAME? NAME: BammaLammaamJam PLAYER 2, WHAT IS YOUR NAME? NAME: Grape Ape BammaLamma 3 am3am, PRESS ENTER TO ROLL DIE. YOU ROLLED A 3. 0 BammaL ammaJamam IS NOW ON SPACE 3 GREAT!YOU BEAT YOUR HIGH SCORE PLAYING TETRIS. DDED $2118.00 TO YOUR ACCOUNT YOU NOW HAVE $2118.00 IN YOUR ACCOUNT.

Explanation / Answer

#include<iostream.h>
#include<conio.h>
#include<time.h>
#include<stdlib.h>
#include <stdio.h>  
#include <Windows.h>

void call();
void one();
void two();
void three();
void four();
void five();
void six();
void call();
int main()
{

//gotoxy(30,15);
cout<<" Author: Arpit Agrawal Description: Dice Roll Algorithm. Project Name: e-Roll. " ;
cout<<" Loading. . . . . . . ";
Sleep(3000);
cout<<" Press r to roll or q to quit the game "<<endl;
char ch;
ch = getch();
xm:
if (ch=='r'){
system("cls");
call(); }
else
exit (0);
cout<<endl<<endl<<"Press r to roll again q to quit!";
ch = getch();
goto xm;
getch();
}

void call()
{
srand (time(NULL));

int n;
n= rand();
n = 1 + n % 6;

switch (n)
{
case 1:
one();
break;
case 2:
two();
break;
case 3:
three();
break;
case 4:
four();
break;
case 5:
five();
break;
case 6:
six();
break;
default:
cout<<"NONUM";

}
}  


void one()
{
cout << " -----" << endl;
cout << "| |" << endl;
cout << "| O |" << endl;
cout << "| |" << endl;
cout << " -----" << endl;
}
void two()
{
cout << " -----" << endl;
cout << "| O|" << endl;
cout << "| |" << endl;
cout << "|O |" << endl;
cout << " -----" << endl;
}
void three()
{
cout << " -----" << endl;
cout << "| O|" << endl;
cout << "| O |" << endl;
cout << "|O |" << endl;
cout << " -----" << endl;
}
void four()
{
cout << " -----" << endl;
cout << "|O O|" << endl;
cout << "| |" << endl;
cout << "|O O|" << endl;
cout << " -----" << endl;
}
void five()
{
cout << " -----" << endl;
cout << "|O O|" << endl;
cout << "| O |" << endl;
cout << "|O O|" << endl;
cout << " -----" << endl;
}
void six()
{
cout << " -----" << endl;
cout << "|O O|" << endl;
cout << "|O O|" << endl;
cout << "|O O|" << endl;
cout << " -----" << endl;
}

#include <iostream>

#include <time.h>

#include <stdlib.h>

using namespace std;

int dieRoll();

int main() {

srand(time(NULL)); //seed number

char re;

cout << "Lets roll some dice! ";

do {

int die1 = dieRoll();

int die2 = dieRoll();

cout << " Your first die is a " << die1 << " Your second die is a " << die2 << endl;

cout << "Your sum of the dice is " << die1 + die2 << endl;

if (die1 == die2) {

cout << " Doubles!";

} else if ((die1 + die2) == 2) {

cout << " Snake Eyes!";

} else {

cout << " Nothing special.";

}

cout << " Would you like to roll again? (y or n) ";

cin >> re;

} while (re == 'y');

}

int dieRoll() {

static int const max = RAND_MAX/6*6;

int r = rand();

while(r >= max) {

r = rand();

}

return r%6+1;

}

#include <iostream>

#include <iomanip>

#include <ctime>

#include <cstdlib>

using namespace std;

void greeting();

void greeting2();

int die1();

int die2();

int dice (int, int);

int results (int);

int main ()

{

  

int counter;

char secondstart;

greeting ();

int firstdie = die1();

greeting2 ();

int secondie = die2();

int total = dice(firstdie, secondie);

results (total);

  

cout << total << endl;

system ("PAUSE");

return 0;

  

  

}

void greeting ()

{

char starter;

cout << "Please press X and then ENTER to roll the die." << endl;

cin >> starter;

}

void greeting2 ()

{

char starter2;

cout << "Please press X again to roll the second die." << endl;

cin >> starter2;

}

int die1()

{

for (int counter = 0; counter < 2; counter++)

{

srand(time(NULL));

for (int i = 0; i <6; i++)

{

cout << rand()% 6+1 << endl;

return rand()%6+1;

}

}   

}

int die2()

{

for (int counter = 0; counter < 2; counter++)

{

srand(time(NULL));

for (int i = 0; i < 6; i++)

{

cout << rand()% 6+1 << endl;

return rand()%6+1;

}

}   

}

int dice (int fdie, int sdie)

{

  

int total = fdie + sdie;

cout << "Your total so far is: " << total << endl;

return total;

}

int results (int total)

{

if (total = 7 && 11)

{

cout << "You won! Congratulations!" << endl;

}

else if (total = 2 && 3 && 12)

{

cout << "You lose. Try again." << endl;

}

else

{

cout << "You may continue to roll." << endl;

greeting ();

int firstdie = die1();

greeting2 ();

int secondie = die2();

int total = dice(firstdie, secondie);

}  

  

cout << total << endl;

}

Edit & Run

Aug 10, 2013 at 10:34am

usandfriends (476)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

#include <iostream>

#include <ctime>

#include <cstdlib>

void greeting(int pnum) {

if(pnum == 1) {

std::cout << "Please press "ENTER" to roll the die.";

} else {

std::cout << "Please press "ENTER" again to roll the second die.";

}

std::cin.ignore();

}

int dieroll(void) {

int ran;

srand(time(NULL));

ran = rand()%6+1;

std::cout << "You rolled a " << ran << "." << std::endl;

return ran;

}

int dice(int fdie, int sdie) {

std::cout << "Your total so far is: " << sdie + fdie << std::endl;

return sdie + fdie;

}

int results(int total) {

if (total == 7 || total == 11) {

std::cout << "You won! Congratulations!";

return 0;

} else if (total == 2 || total == 3 || total == 12) {

std::cout << "You lose. Try again.";

return 0;

} else {

std::cout << "You may continue to roll." << std::endl << std::endl;

return 1;

}

}

int main(void) {

int counter, total, seconddie, firstdie;

char secondstart;

do {

greeting(1);

firstdie = dieroll();

greeting(2);

seconddie = dieroll();

total = dice(firstdie, seconddie);

} while(results(total)!=0);

std::cin.ignore();

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote