Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 136,108 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,716 people online right now. Registration is fast and FREE... Join Now!




Dice Game

 
Reply to this topicStart new topic

Dice Game, I'm having problems with detecting the numbers

nineball_ssj9
3 Oct, 2007 - 06:22 PM
Post #1

New D.I.C Head
*

Joined: 3 Oct, 2007
Posts: 1


My Contributions
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream.h>

int rollDice()
{
return ((rand() % 6) + 1);
}

int main()
{
char C='c';

do
{
int dice1=rollDice();
int dice2=rollDice();
int point = dice1+dice2;

printf("\n You rolled: %d, %d, %d", dice1, dice2, point);

if((point == 7) || (point == 11))
{
printf("\n You Win ");
printf("\n press r to roll again ");
cin>>C;
}
else
{
if((point == 3) || (point == 2) || (point == 12))
{
printf("\n You Lose ");
printf("\n press r to roll again ");
cin>>C;
}

else
{
printf("\n Press r to roll ");
cin >> C;

int temp = rollDice() + rollDice();
if(temp == point)
{
printf("\n You Win! ");
}
else
{
if(temp == 7)
{
temp = rollDice() + rollDice();
printf("\n You Lose ");
}
/** while(temp!=7)
{
temp = rollDice() + rollDice();
}
// printf("\n You Lose ");**/
}
}
}
}
while(C!='e');
return 0;
}
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Dice Game
3 Oct, 2007 - 06:29 PM
Post #2

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,441



Thanked: 64 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
You need to initialize int rollDice() before you actually code it.

CODE

#include <stdio.h>

int rollDice(void);

int main(void) {
...
}

int rollDice() {
  return ((rand() % 6) + 1);
}


This post has been edited by no2pencil: 3 Oct, 2007 - 06:30 PM
User is online!Profile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 09:23PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month