Program Help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2007
Posts: 11
Reputation: NicAuf is an unknown quantity at this point 
Solved Threads: 0
NicAuf NicAuf is offline Offline
Newbie Poster

Program Help

 
0
  #1
Sep 24th, 2007
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

  1. //Name: Nick Auffarth
  2. //Class: CS140-003
  3. //Assignment: Program 2
  4. //Date: September 24, 2006
  5. #include <iostream>
  6. #include <iomanip>
  7. #include <ctime>
  8. #include <string>
  9. using namespace std;
  10.  
  11.  
  12.  
  13. void main()
  14. {
  15. srand((unsigned)time(NULL));
  16.  
  17. int die;
  18. string name1, name2, name3;
  19.  
  20.  
  21. cout << "Programmed by Nick Auffarth" << endl << endl;
  22. cout << "The first person to roll a total of 20 wins." << endl;
  23. cout <<"If more than two cross the 20 mark, then the one with the highest" << endl;
  24. cout << "total wins." << endl << endl;
  25. cout <<"Enter Player One's First Name: ";
  26. cin >> name1;
  27. cout <<"Enter Player Two's First Name: ";
  28. cin >> name2;
  29. cout <<"Enter Player Three's First Name: ";
  30. cin >> name3;
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39. cout<<setw(10);
  40. cout<<"x"<<endl;
  41.  
  42.  
  43. }
Last edited by NicAuf; Sep 24th, 2007 at 11:06 am. Reason: Added code tags
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 47
Reputation: teppuus is an unknown quantity at this point 
Solved Threads: 0
teppuus's Avatar
teppuus teppuus is offline Offline
Light Poster

Re: Program Help

 
0
  #2
Sep 24th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 11
Reputation: NicAuf is an unknown quantity at this point 
Solved Threads: 0
NicAuf NicAuf is offline Offline
Newbie Poster

Re: Program Help

 
0
  #3
Sep 24th, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 47
Reputation: teppuus is an unknown quantity at this point 
Solved Threads: 0
teppuus's Avatar
teppuus teppuus is offline Offline
Light Poster

Re: Program Help

 
0
  #4
Sep 24th, 2007
In my book, it says you have to use the header file cstdlib to use function rand to generate a random number. Do you think using #include<cstdlib> would help? Wasn't sure since your instructions mentioned ctime header file...maybe they are similar.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 11
Reputation: NicAuf is an unknown quantity at this point 
Solved Threads: 0
NicAuf NicAuf is offline Offline
Newbie Poster

Re: Program Help

 
0
  #5
Sep 24th, 2007
I don;t know but I'll try it see if that works.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 11
Reputation: NicAuf is an unknown quantity at this point 
Solved Threads: 0
NicAuf NicAuf is offline Offline
Newbie Poster

Re: Program Help

 
0
  #6
Sep 24th, 2007
I still get the same numbers.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 47
Reputation: teppuus is an unknown quantity at this point 
Solved Threads: 0
teppuus's Avatar
teppuus teppuus is offline Offline
Light Poster

Re: Program Help

 
0
  #7
Sep 24th, 2007
hmm, ok. I'll keep looking to see if I can find something that might explain that.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 47
Reputation: teppuus is an unknown quantity at this point 
Solved Threads: 0
teppuus's Avatar
teppuus teppuus is offline Offline
Light Poster

Re: Program Help

 
0
  #8
Sep 24th, 2007
Here is a description about getting a new random number each time: http://www.cplusplus.com/reference/c...lib/srand.html
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 47
Reputation: teppuus is an unknown quantity at this point 
Solved Threads: 0
teppuus's Avatar
teppuus teppuus is offline Offline
Light Poster

Re: Program Help

 
0
  #9
Sep 24th, 2007
I ran that example program on that webpage, and it did change the random number (after running the program twice). It seems you have to change the srand value from srand ( time(NULL) ); to srand (1); after rolling the die.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 11
Reputation: NicAuf is an unknown quantity at this point 
Solved Threads: 0
NicAuf NicAuf is offline Offline
Newbie Poster

Re: Program Help

 
0
  #10
Sep 24th, 2007
I am so lost..........
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC