# Hi and a question

• 11-13-2012
jeckel7234
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; }```
• 11-13-2012
jeckel7234
? anybody
• 11-14-2012
Salem
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.