My code only worked for 3 test cases and failed for other 2. What's wrong in my code?

You are given N golden balls,you have to find the maximum height of triangle it can form with that balls.

A traingle with height X will have X balls in the bottom most level and 1 ball in the top most level

each upper level will have exactly one ball less than its bottom level.

//here’s my code
int main()
int t;
long long int n;
float h;
return 0;

here in this part of the code try this :
h=(-1+sqrt(1+8*n)/2; ===> h = (-1 + (sqrt(1 + 8 * n)) / 2;