# Need help with Craps program

• 04-16-2008
green11420
Need help with Craps program
I am doing a Craps program in my class. I think this is a very common program for beginners but it seems to be different everywhere I see it. All I need it to do is the user inputs the first total, it tells them if they win or lose, if not, it prompts a second total and checks for a winner. If it is not a winner, it prompts for another roll from the user until the user wins. I got my code to compile correctly but I have some problems.

Problem 1: If the first number is a winner or a loser, it prints "You win!!!" or "You Lose!!!" and then it does not end the program. I have to actually close the program myself.

Problem 2: If the first number is neither a winner or a loser, it prompts for a second roll. If the second roll is the same as the first it says "You win!!!" If not, it should ask for another roll, instead it asks for another roll infinitly, I have to close the program.

Here is my code, I have been working with it for a while and I would really appreciate any help.

Code:

```// File: CRAPS.cpp // Author: Emil // Class: TR 5pm // Purpose: To simulate a game of Craps given total on first dice roll // and possibly a second dice roll. #include <iostream> using namespace std; int main() {         float first_total,                         second_total,                         roll_total;                                 // Prompt for and read in total from first dice roll         cout << "Enter total from first dice roll (2-12)... ";         cin >> first_total;         if((first_total == 7) || (first_total == 11))                 cout << "You Win!!!";                 else                        if((first_total == 2) || (first_total == 3) || (first_total == 12))                                 cout << "You Lose!!!";                 else                                                         cout << "Please roll again and enter total of second roll (2-12): ";                                 cin >> second_total;                 if(second_total == first_total)                                 cout << "You win!!!";                         else                                if(second_total == 7)                                                 cout << "You lose!!!";                                 else                         while ((second_total != 7) || (second_total == first_total))                                                         cout << "Please roll again and enter total on this roll (2-12): ";                                 cin >> roll_total;                                                 second_total = roll_total;                                                         return (0); }```
• 04-16-2008
Daved
You are missing braces around your code blocks.
• 04-16-2008
vart
why you are using float vars to store integer values? use ints