Hi and a question

This is a discussion on Hi and a question within the C++ Programming forums, part of the General Programming Boards category; Hi everyone, im relatively new to programming. I'm having an issue with some code ive written, after the program opens ...

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    2

    Hi and a question

    Hi everyone, im relatively new to programming.

    I'm having an issue with some code ive written, after the program opens and I input my first bit of data, it closes down and i'm having trouble keeping it open

    Thanks for any suggestions/help

    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <cmath>
    #include <cstdlib>
    #include <cfloat>
    #include <iomanip>
    #include <stdlib.h>
    #include <time.h>
    #include <conio.h>
    
    
    using namespace std;
    
    
    float doBreak ();
    float doProbability (float, float);
    
    
    const int SENTINEL = 21;		//sentinal value
    
    
    
    
    int main()
    {
    	float count;
    	float tests;
    	float probability;
    	float triangle = 0;
    	
    
    
    	count = 1;
    	srand (time (NULL));
    
    
    	cout << "Enter number of glassrods to demolish (Enter " << SENTINEL << " to end program): ";
    	cin >> tests;
    
    
    	if 
    	(tests != SENTINEL)
    	{
    		do
    		{
    			triangle = triangle + doBreak();
    			count++;
    		}while (count <= tests);
    
    
    	probability = doProbability(triangle, tests);
    	
    	cout << "The probability that the broken glass rods will form a triangle is: " << probability << "%" << endl;
    	}
    	else
    	{
    			cout << "Aww, I was hoping to break stuff..." << endl;
    	}
    	return 0;
    }
    
    
    float doBreak()
    {
    	float break1;
    	float break2;	
    	float side1;
    	float side2;
    	float side3;
    	
    	
    	
    	
    		
    	break1 = (float)rand()/RAND_MAX;
    	break2 = (float)rand()/RAND_MAX;
    	
    	if (break1 < break2)
    	{
    		side1 = break1;
    		side2 = (break2 - break1);
    		side3 = 1 - break2;
    	}
    	else
    	{	
    		side1 = break2;
    		side2 = (break1 - break2);
    		side3 = 1 - break1;
    	}
    	if
    	((side1 + side2) > side3 &&
    	(side1 + side3) > side2 &&
    	(side2 + side3) > side1)
    	{
    		return 1;
    	}
    	else
    	{
    		return 0;
    	}
    }
    	
    float doProbability 
    	(float triangle,
    	float tests)
    	
    {
    	float probability;
    	
    	probability = (triangle / tests) * 100;
    	return probability;
    }

  2. #2
    Registered User
    Join Date
    Nov 2012
    Posts
    2
    ? anybody

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,824
    FAQ > Stop my Windows Console from disappearing everytime I run my program? - Cprogramming.com

    Also, your IDE may have a "keep window open at program exit", which is preferred, since it doesn't involve you changing your source code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-23-2011, 10:00 AM
  2. *szString = things question/memory question
    By Jang in forum C Programming
    Replies: 3
    Last Post: 01-20-2011, 04:59 AM
  3. Newbish Question file reading question....
    By kas2002 in forum C Programming
    Replies: 23
    Last Post: 05-17-2007, 01:06 PM
  4. Self regiserting DLLs question and libraries question.
    By ApocalypticTime in forum Windows Programming
    Replies: 2
    Last Post: 03-22-2003, 02:02 PM
  5. A question of color...(not a racial question)
    By Sebastiani in forum Windows Programming
    Replies: 7
    Last Post: 01-15-2003, 08:05 PM

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