C++ Dice Rolling

Discussion in 'Programming' started by nineball_ssj9, Oct 3, 2007.

  1. #1
    I need help with fixing my code, i'm trying to make a Dice Game, but i'm not making it right

    #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;
    }
     
    nineball_ssj9, Oct 3, 2007 IP