help on craps

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nemesis
    New Member
    • Aug 2006
    • 1

    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+random 2);
    }

    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\nWEL COME TO CRAPS!!\n\n");
    printf("\nInstr uctions & 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("\nInval id 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)||(strcm p(ans1, "y")==0)) {
    bet();
    done1=1;
    break; }
    else if ((strcmp(ans1," N")==0)||(strcm p(ans1, "n")==0)) {
    printf("Thank you for playing craps!");
    done1=1;
    break;}
    else
    printf("\nInval id 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)||(strcm p(ans2, "y")==0)) {
    main();
    done2=1;
    break; }
    else if ((strcmp(ans2," N")==0)||(strcm p(ans2, "n")==0)) {
    done2=1;
    printf("Thank you for playing craps!");
    break; }
    else
    printf("\nInval id 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("\nInval id Wager - only number between 1 and 1000\n");
    printf("Make your wager (1-1000):");
    scanf("%d", &wager); }

    sum=diceroll(ra ndom1, 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(r andom1, 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]
  • axas
    New Member
    • Jul 2006
    • 32

    #2
    in which function you have problem?

    Comment

    Working...