This is a pretty basic program that inputs the sides of a triangle, and determines what kind it is, and what the area is. I've been having some issues with my do-While - I have a prompt at the end of my code, just before the "while," that asks the user if they want to continue...I've been getting infinite loops.
Right now, it's giving me seg faults. Would definitely appreciate the help.
#include <stdio.h>
#include <math.h>
int main(void){
int side1;
int side2;
int side3;
int userInput = 0;
float s, area;
printf("This program will input three sides of a triangle, and then will determine whether it is an Equilateral, Isosceles , Scalene, or neither");
do{
printf("\n\nPlease enter the three sides of your triangle, separated by spaces: ");
scanf("%d %d %d", &side1, &side2, &side3);
fflush(stdin);
if (side1 < 0 || side2 < 0 || side3 < 0)
{
printf("Error: Please enter positive integers.");
}
if (side1 == side2 && side2== side3)
{
printf("\nYou have an Equilateral triangle.");
}
elseif (side1 == side2 || side2 == side3 || side1 == side3 )
{
printf("\nYou have an Isosceles triangle.");
}
else
{
printf("\nYou have a Scalene triangle");
}
s = (side1 + side2 + side3) / 2.0;
area = sqrt((s * (s - side1) * (s - side2) * (s - side3)));
printf("\n\nThe area of the triange is %f.", area);
printf("\n\nIf you would like to continue, enter any number. If you wish to quit, enter 99.");
scanf("%d", userInput);
fflush(stdin);
}
while (userInput != 99);
return 0;
}
Last question is that my professor insisted on flushing the buffer after input is taken. I tried the program both with and without "fflush(stdin);" (on lines 23 and 57) after taking input, and the result is the same. Not sure if I'm doing something wrong there.