473,387 Members | 1,561 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

help on craps

help!!!
IMy problem is that I don't know how to make the increase/decrease part work.
The specification given to me by my teacher was: if the layer wins, double the wager (done!), and if loses , decrease the wager by the value entered by the player(done also!).
fot each continuation of the game, the player must be asked if he wants to increase/ decrease the wager, he must enter a new value. otherwise the wager remains the same. (I can't do that! Pls. help me!).

here's my code (pardon my code for being messy.. and i think my functions are all wrong.. :( )
[PHP]
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <stream.h>

int wager, random1, random2, sum, sum1, point, total;
int done, done1, done2, done3;
char ans[5], ans1[5], ans2[5], ans3[5];

int diceroll (int random1, int random2)
{
int dc1, dc2;

printf("\nPress a key to roll a dice.\n");
getch();
printf("Rolling a dice...\n");
getch();

srand((unsigned)time(NULL));

for(dc1=0; dc1<1; dc1++) {
printf("\nThe spot on the first dice is:");
random1 = (rand()%6)+1;
cout << random1 << endl; }

for(dc2=0; dc2<1; dc2++) {
printf("The spot on the second dice is:");
random2 = (rand()%6)+1;
cout << random2 << endl; }

return (random1+random2);
}

int win(int total, int wager)
{
return (total += (wager*2));
}

int lose(int total, int wager)
{
total -= wager;
if (total<=0)
return 0;
else
return (total -= wager);
}

void rules(void)
{
printf("\n\nWELCOME TO CRAPS!!\n\n");
printf("\nInstructions & Rules:\n");
printf("Player rolls two dice. After the dice has come to rest, the sum of the spots on the 2 upward face is calculated.\n");
printf("To win: The sum of faces is 7 or 11 after a roll.\n");
printf("To get a craps/lose: The sum of faces is 2, 3 or 12 after a roll.\n");
printf("To make a point: The sum of faces is 4, 5, 6, 8, 9, or 10 after a roll.\n");
printf("After making a point, player must continue rolling until dice achieve the same 'point value', to win.\n");
printf("But if sum of faces is 7 before player achieve the same 'pont value', player lose.\n\n");
}

int bet(void)
{
done3=0;
while(!done2){
printf("\nDo you want to increase or decrease your wager? <I, D or N>:");
scanf("%s", ans3);
if (strcmp(ans3,"I")==0) {
done3=1;
break; }
else if (strcmp(ans3,"D")==0) {
done3=1;
break; }
else if (strcmp(ans3,"N")==0) {
done3=1;
break; }
else
printf("\nInvalid Character - I, D, N only.");
done3=0;
break;
}
}

void cont(void)
{
done1=0;
while (!done1){
printf("\nDo you want to continue playing (Y or N)?");
scanf("%s", ans1);
if ((strcmp(ans1,"Y")==0)||(strcmp(ans1, "y")==0)) {
bet();
done1=1;
break; }
else if ((strcmp(ans1,"N")==0)||(strcmp(ans1, "n")==0)) {
printf("Thank you for playing craps!");
done1=1;
break;}
else
printf("\nInvalid Character - Y or N only.");
done1=0;
break;
}
}



void newg(void)
{
done2=0;
while (!done2){
printf("\nDo you want to play a new game (Y or N)?");
scanf("%s", ans2);
if ((strcmp(ans2,"Y")==0)||(strcmp(ans2, "y")==0)) {
main();
done2=1;
break; }
else if ((strcmp(ans2,"N")==0)||(strcmp(ans2, "n")==0)) {
done2=1;
printf("Thank you for playing craps!");
break; }
else
printf("\nInvalid Character - Y or N only.");
done2=0;
break;
}
}


main()
{
rules();

printf("\nMake a wager (1-1000):");
scanf("%d", &wager);
while ((wager>1000)||(wager<1)) {
printf("\nInvalid Wager - only number between 1 and 1000\n");
printf("Make your wager (1-1000):");
scanf("%d", &wager); }

sum=diceroll(random1, random2);
printf("Their sum is :%d\n", sum);

switch(sum)
{
case 7: case 11:
printf("You win! You now have %d\n", win(total, wager));
cont();
break;
case 2: case 3: case 12:
printf("CRAPS! You Lose! You now have %d\n", lose(total, wager));
{
if (total<=0) {
printf("You cannot play anymore.\n");
newg(); }
else
cont();
break;
}
default:
point=sum;
done=0;
while(!done){

sum1=diceroll(random1, random2);
printf("Their sum is :%d\n", sum1);

if (sum1==point){
printf("You win! You now have %d.\n", win(total, wager));
cont();
break; }
else if (sum1==7) {
printf("You Lose! You now have %d.\n", lose(total, wager));
{
if (total<=0) {
printf("You cannot play anymore.\n");
newg(); }
else
cont();
}
done=1; }
else
done=0;
}
}
}


[/PHP]
Aug 20 '06 #1
1 4886
axas
32
in which function you have problem?
Aug 21 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jamie Bissett | last post by:
I have written an installer class that I invoke as a custom action. I have asses 2 screens in the installation process that pass data to this Installer Class. I have succesfully debugged the...
6
by: tigrfire | last post by:
I've been working on a program to try and play a game of Craps, based on a version I found elsewhere - I didn't code the original, but I added a few things such as a balance and wager system. I'm...
1
by: lblock | last post by:
i have this code that plays the game of craps, but i need to be able to take how much they brought and how much they want to bet. show the number on the dice and tell them it they won or lose and...
4
by: wishwish20 | last post by:
I am having a problem with my Database. I am having an issue with being able to update a set of records. What I need is a way to uncheck a checkbox in the underlying table in this query. The # of...
1
by: lenest | last post by:
I need help writing a program.... You are to write a python program to accomplish the following: a.. Play a dice game of Craps using a random number generator to simulate the roll of the...
0
by: rocky666 | last post by:
if someone can help me with this problem i would really be greatful, thx. Write a program to simulat the dice game, Craps. The rules are that a player rolls 2 dice. The total number rolled is...
3
by: whitehatmiracle | last post by:
SOS When i comile this program, im getting 13 errors all saying "prompt_for_bet and get_bet are not memebers of class Player" Where am i going wrong? Can anyone plzz enlighten me? Thnking u...
3
by: TamaThps | last post by:
I have to write a program that lets the user play the game of Craps. As of right now it is incomplete and I have run into some errors. It's my first time using functions instead of the program all...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.