~'Untitled Clan
Would you like to react to this message? Create an account in a few clicks or log in to continue.



 
HomeLatest imagesSearchRegisterLog in

 

 I need C++ Help!!!

Go down 
+3
regedit
childofblood
Marshmellow
7 posters
AuthorMessage
Marshmellow

Marshmellow


Posts : 2299
Join date : 2010-10-16
Age : 32

I need C++ Help!!! Empty
PostSubject: I need C++ Help!!!   I need C++ Help!!! Icon_minitimeThu Mar 08, 2012 9:42 am

Can anyone help me? Please?

The game of 50/50 is a simple two person dice game in which the first player to reach 50 or more points wins. Players take turns. On each turn a player rolls a six-sided die. After each roll:
• If the player rolls a 2- 6 then he can either:
o Roll again or
o Hold (at this point the sum of all rolls made this turn are added to the players total score and it becomes the others players turn)
• If the player rolls a 1 then the player loses his turn. He/She gets no new points and it becomes the opponent’s turn.
If the player reaches 50 or more points after holding then the player wins.

Write a program that plays the game of 50/50, where one player is a human and the other is the computer. Allow the human to roll first. Allow the human to input “r” to roll again or “h” to hold.

The computer should play according to the following rule: keep rolling on its turn until it has accumulated 15 or more points, then hold. Of course, if the computer rolls a 1 then the turn ends immediately.

Write your program with at least two functions:
int humanTurn( );
int computerTurn( );

The functions should perform the necessary logic to handle a single turn for either the computer or the human. The functions should return the turn total to be added to the total score upon competition of the turn. For example if the human rolls a 3 and 6 and then holds, then humanTurn should return 9. However if the human rolls a 3 and 6 and 1 then the function should return 0.
.
Requirements

The program will require the following parts:

• Utilize the random number generator to generate random dice value in each roll
• Display the dice value after each roll and display the total points after each turn
• When game is over, display who is the winner and the total points of the winner.
• Handling of any invalid human input data
• Commented code including your name and a description of the program

Notes, the sample executable program is on the VLT. You may download and try it first.

Deliverables

You will upload the following items in a zip file into the “P2” folder on VLT:
1) Completed source code (.cpp file) with comments
2) Short document with a description of your program, UML activity diagram, and 3 screenshots of different sample runs of your program

Notes
• Don’t forget about the srand function "srand(time(NULL));"
• Review the RandomTimeFunction slides and UML slides if need


Last edited by Marshmellow on Fri Mar 09, 2012 1:20 pm; edited 1 time in total
Back to top Go down
childofblood




Posts : 85
Join date : 2011-12-03
Age : 31

I need C++ Help!!! Empty
PostSubject: Re: I need C++ Help!!!   I need C++ Help!!! Icon_minitimeThu Mar 08, 2012 11:07 am

Uhh... not a clue Marsh, sorry.
Back to top Go down
Marshmellow

Marshmellow


Posts : 2299
Join date : 2010-10-16
Age : 32

I need C++ Help!!! Empty
PostSubject: Re: I need C++ Help!!!   I need C++ Help!!! Icon_minitimeThu Mar 08, 2012 11:46 am

I think this is the random number generator in terms of dice:

#include <cstdlib>
#include <ctime>
#include <iostream>

using namespace std;

int main()
{
srand((unsigned)time(0));

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

cout << i << "\n";

}


Now I need help on adding the if/thens and while functions... -_-
Back to top Go down
regedit
Clan Member
Clan Member



Posts : 498
Join date : 2009-08-24
Age : 27
Location : London, England

I need C++ Help!!! Empty
PostSubject: Re: I need C++ Help!!!   I need C++ Help!!! Icon_minitimeThu Mar 08, 2012 12:10 pm

Don't know how many people here know C++.
Tru might be able to help, but if not try asking on arma forums.
Back to top Go down
Marshmellow

Marshmellow


Posts : 2299
Join date : 2010-10-16
Age : 32

I need C++ Help!!! Empty
PostSubject: Re: I need C++ Help!!!   I need C++ Help!!! Icon_minitimeThu Mar 08, 2012 12:48 pm

Thanks reg, I'll go post it
Back to top Go down
Windrider
Clan Member
Clan Member



Posts : 2266
Join date : 2009-08-23

I need C++ Help!!! Empty
PostSubject: Re: I need C++ Help!!!   I need C++ Help!!! Icon_minitimeThu Mar 08, 2012 4:16 pm

oO my dad is pro at C++ but I don't know much soz
Back to top Go down
Axis

Axis


Posts : 65
Join date : 2011-10-26
Location : less

I need C++ Help!!! Empty
PostSubject: Re: I need C++ Help!!!   I need C++ Help!!! Icon_minitimeFri Mar 09, 2012 8:45 am

so i dont have any experienceworking in c++ but just breakdown the problem.

Is the number generating working form 1 - 6

if so the are you displaying the outcome

after i would likely start with the playerturn()

playerturn{

number = diceroll()

if diceroll <2;

while( wait for user);
If "hold" then total()

else number = diceroll

else: end player turn

}

clearly the wrong syntax, but the program it self isnt hary hard if you break it down.







Back to top Go down
Marshmellow

Marshmellow


Posts : 2299
Join date : 2010-10-16
Age : 32

I need C++ Help!!! Empty
PostSubject: Re: I need C++ Help!!!   I need C++ Help!!! Icon_minitimeFri Mar 09, 2012 1:20 pm

Axis wrote:


playerturn{

number = diceroll()

if diceroll <2;

while( wait for user);
If "hold" then total()

else number = diceroll

else: end player turn

}

clearly the wrong syntax, but the program it self isnt hary hard if you break it down.


This is what I have so far with the computer part:

#include <cstdlib>
#include <ctime>
#include <iostream>

using namespace std;

int main() {
int computerTurn() {

srand(time(0));

int DieRoll;
DieRoll = rand()/((RAND_MAX/6)+1);
cout << DieRoll << endl;

while (DieRoll > 1) {
cout << DieRoll << endl;
}
else {
cout << 0 << endl;
}

if (DieRoll < 15) {
DieRoll++;
}
else {
break;
}

}
system ("PAUSE");
return 0;
}


I feel like the human player would be the same except without the >15 requirement and with the "hold" or "roll" option.
How do I put in the option for the player to choose?
And how do I make it so it adds up after each turn?
Back to top Go down
Axis

Axis


Posts : 65
Join date : 2011-10-26
Location : less

I need C++ Help!!! Empty
PostSubject: Re: I need C++ Help!!!   I need C++ Help!!! Icon_minitimeFri Mar 09, 2012 8:08 pm

make an intermedite variable in the step where it calls for a random number

so like if it is between 2 and 6 then set turnRoll = Dieroll

and for if dieroll = 1 then set turnRoll = 0

at the end of the turn add turnRoll to PlayerScore or ComputerScore for example.



for the inputs i have no clue, you need to find out how c++ handles user input
Back to top Go down
sexybeast
Clan Member
Clan Member



Posts : 2738
Join date : 2009-11-03
Age : 33
Location : Michigan

I need C++ Help!!! Empty
PostSubject: Re: I need C++ Help!!!   I need C++ Help!!! Icon_minitimeFri Mar 09, 2012 8:38 pm

i think the cin command works for inputs by the human and you should make sure to declare the variables in the beginning of the program so that they are set to the correct value when they are used c++ likes to assign random shit into them if you dont(at least thats how i did it)
Back to top Go down
Anarchy

Anarchy


Posts : 319
Join date : 2011-09-18

I need C++ Help!!! Empty
PostSubject: Re: I need C++ Help!!!   I need C++ Help!!! Icon_minitimeSat Mar 10, 2012 12:43 pm

i haven't read all this yet, but i know duke from rx can program hell good, (:D happy fun times) idk what he can do though.
Back to top Go down
regedit
Clan Member
Clan Member



Posts : 498
Join date : 2009-08-24
Age : 27
Location : London, England

I need C++ Help!!! Empty
PostSubject: Re: I need C++ Help!!!   I need C++ Help!!! Icon_minitimeSun Apr 01, 2012 3:39 am

how did this go marsh?
Back to top Go down
Marshmellow

Marshmellow


Posts : 2299
Join date : 2010-10-16
Age : 32

I need C++ Help!!! Empty
PostSubject: Re: I need C++ Help!!!   I need C++ Help!!! Icon_minitimeSun Apr 01, 2012 9:42 pm

I figured I'd wait til I take a programming course to learn this instead of teaching myself, lol
Back to top Go down
regedit
Clan Member
Clan Member



Posts : 498
Join date : 2009-08-24
Age : 27
Location : London, England

I need C++ Help!!! Empty
PostSubject: Re: I need C++ Help!!!   I need C++ Help!!! Icon_minitimeMon Apr 02, 2012 6:06 am

If you haven't already heard of it you might find http://projecteuler.net interesting.
Back to top Go down
Marshmellow

Marshmellow


Posts : 2299
Join date : 2010-10-16
Age : 32

I need C++ Help!!! Empty
PostSubject: Re: I need C++ Help!!!   I need C++ Help!!! Icon_minitimeMon Apr 02, 2012 11:15 am

I'll check it out, thanks reg :)
Back to top Go down
Sponsored content





I need C++ Help!!! Empty
PostSubject: Re: I need C++ Help!!!   I need C++ Help!!! Icon_minitime

Back to top Go down
 
I need C++ Help!!!
Back to top 
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
~'Untitled Clan  :: ~'Untitled Clan. :: Chat-
Jump to: