Originally Posted by

**CoryMore**
I believe it is, after adding a print out:

Code:

if
((side1 + side2) > side3 &&
(side1 + side3) > side2 &&
(side2 + side3) > side1)
{
triangle += 1;
cout << triangle << endl;
}
return triangle;
}

I get:

$ ./rods

Enter number of glassrods to demolish (Enter 21 to end program): 100

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

The probability that the broken glass rods will form a triangle is: 30%

I see you got it working as I was commenting about it (which I edited).

Good job!

Since the 'triangle' count value is only used in main(), that could be a logical place to

maintain it. Then doBreak() only needs to return 0 (no triangle) or 1 (triangle formed).

You could remove the 'triangle' variable completely from doBreak() and change this part:

Code:

if
((side1 + side2) > side3 &&
(side1 + side3) > side2 &&
(side2 + side3) > side1)
{
triangle += 1;
}
return triangle;

to this:

Code:

if
((side1 + side2) > side3 &&
(side1 + side3) > side2 &&
(side2 + side3) > side1)
return 1;
else
return 0;

Then, in main(), just declare:

float triangle = 0;

and use:

triangle = triangle + doBreak();