•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,515 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,726 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 730 | Replies: 13
![]() |
•
•
Join Date: Sep 2007
Posts: 11
Reputation:
Rep Power: 2
Solved Threads: 0
Ok so my first thread got deleted, due to spam. However, I still need help with my program. So here's my program description.
Electronic submission: You are to electronically submit your assignment through Moodle at clasess.cs.siue.edu.
Objectives: Loops and decisions.
Problem Description
Write a program to simulate a game of dice rolling. The dice will be rolled by three players, with each player rolling one die each. Each player will continue rolling a die and adding its value to their total up to that point. The player whose total goes over twenty first wins. To generate the player’s roll, a random number generator will be used, as shown below.
If two players go over twenty with the same roll, then the player with the largest number wins. If the two winners have the same number, then it is a tie. Remember there can be three way ties, also.
After each player rolls, the program should display a vertical graph of each player’s total points to pictorially show who is winning at that point.
In order to randomly “throw” the die, you must include the following statements:
Include the following prototypes:
#include<ctime>
The following should be the first statement in main():
srand((unsigned)time(NULL));
When you need to roll the die:
die = (rand() % 6) + 1; // die is a variable name that you made up
I am suppose to use X's to keep tally of the score, using setw().
Also here's my code so far, which isn't that far along at all, due to the fact that I am not a good programmer when dealing with complex programs. I know this probably isn't that hard but for me it it. So any help would be great
Electronic submission: You are to electronically submit your assignment through Moodle at clasess.cs.siue.edu.
Objectives: Loops and decisions.
Problem Description
Write a program to simulate a game of dice rolling. The dice will be rolled by three players, with each player rolling one die each. Each player will continue rolling a die and adding its value to their total up to that point. The player whose total goes over twenty first wins. To generate the player’s roll, a random number generator will be used, as shown below.
If two players go over twenty with the same roll, then the player with the largest number wins. If the two winners have the same number, then it is a tie. Remember there can be three way ties, also.
After each player rolls, the program should display a vertical graph of each player’s total points to pictorially show who is winning at that point.
In order to randomly “throw” the die, you must include the following statements:
Include the following prototypes:
#include<ctime>
The following should be the first statement in main():
srand((unsigned)time(NULL));
When you need to roll the die:
die = (rand() % 6) + 1; // die is a variable name that you made up
I am suppose to use X's to keep tally of the score, using setw().
Also here's my code so far, which isn't that far along at all, due to the fact that I am not a good programmer when dealing with complex programs. I know this probably isn't that hard but for me it it. So any help would be great
//Name: Nick Auffarth
//Class: CS140-003
//Assignment: Program 2
//Date: September 24, 2006
#include <iostream>
#include <iomanip>
#include <ctime>
#include <string>
using namespace std;
void main()
{
srand((unsigned)time(NULL));
int die;
string name1, name2, name3;
cout << "Programmed by Nick Auffarth" << endl << endl;
cout << "The first person to roll a total of 20 wins." << endl;
cout <<"If more than two cross the 20 mark, then the one with the highest" << endl;
cout << "total wins." << endl << endl;
cout <<"Enter Player One's First Name: ";
cin >> name1;
cout <<"Enter Player Two's First Name: ";
cin >> name2;
cout <<"Enter Player Three's First Name: ";
cin >> name3;
cout<<setw(10);
cout<<"x"<<endl;
} Last edited by NicAuf : Sep 24th, 2007 at 11:06 am. Reason: Added code tags
I am a newbie too at this programming stuff. Maybe we can work on the algorithm together to help get you started? Do you want the program to "roll" the dice three times before it displays the results of all three players? Or roll once, and then display one result before rolling again? I figured either one of those would be the next step in your algorithm after you entered the players names.
•
•
Join Date: Sep 2007
Posts: 11
Reputation:
Rep Power: 2
Solved Threads: 0
Yeah I want the program to roll the dice once for each player, show the result of the row, dispalys x's in a column that corresponds with the number rolled. I need to keep doing this until one of them "wins." There hardest part I have is the rolling of the die, when ever it rolls I get the same number for each player. Also I need the x's in the columns to correspond with each new sum.
Here is a description about getting a new random number each time: http://www.cplusplus.com/reference/c...lib/srand.html
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Playing .Wav/MIDI files in a Visual Basic Program (Visual Basic 4 / 5 / 6)
- What's the HARDEST program you've written? (Computer Science and Software Design)
- Cool little Program to disable startup programs (Windows NT / 2000 / XP / 2003)
- Program is shutting down right after program is executed (C++)
- 3d Program (Game Development)
Other Threads in the C++ Forum
- Previous Thread: Tutorial Help =(
- Next Thread: Strings and the new operator?


Linear Mode