Need help with Craps program

This is a discussion on Need help with Craps program within the C++ Programming forums, part of the General Programming Boards category; I am doing a Craps program in my class. I think this is a very common program for beginners but ...

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    18

    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);
    }

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

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    why you are using float vars to store integer values? use ints
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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, 12: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, 12:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21