I am trying to make a program which would generate 3 sides given following input: longest allowed hypotenuse and number of triangles required. The sides can be only integers. The program I have written just hangs on me and does not return any output. If you are to downvote me explain why.
#include <iostream>
#include <cmath>
#include <cstdlib>
int generator(int number, int hypoth){
int a,b,c;
while (number>0){
c=rand()%(hypoth-1)+1;
for (a=1;a<hypoth-2;a++){
for (b=1;pow(a,2)+pow(b,2)<=pow(c,2); b++){
if (pow(a,2)+pow(b,2)==pow(c,2)){
std::cout<<"sides: "<<a<<" "<<b<<" "<<c<<std::endl;
number--;
}
}
}
}
return 0;
}
int main(){
int triangle_number, hypothenuse;
std::cout << "How many triangles to generate? ";
std::cin >> triangle_number;
std::cout << "How long is max hypothenuse?";
std::cin >> hypothenuse;
generator(triangle_number, hypothenuse);
return 0;
}
If you think I should improve my algorithm please hint me in right direction. Thank you for your time.