Thread: Need help with Craps program

  1. #1
    Registered User
    Join Date
    Mar 2008

    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.

    // 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,
    	// 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!!!";
    		if((first_total == 2) || (first_total == 3) || (first_total == 12))
    			cout << "You Lose!!!";
    				cout << "Please roll again and enter total of second roll (2-12): ";
    				cin >> second_total;
    	if(second_total == first_total)
    		cout << "You win!!!";
    		if(second_total == 7)
    			cout << "You lose!!!";
    			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);

  2. #2
    Registered User
    Join Date
    Jan 2005
    You are missing braces around your code blocks.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    why you are using float vars to store integer values? use ints
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM