For starters, heed your compiler warnings. This is what I got when I built your code.
Code:
main.c||In function 'main':|
main.c|25|warning: format '%d' expects type 'int', but argument 2 has type 'double'|
main.c|33|warning: format '%d' expects type 'int', but argument 2 has type 'double'|
main.c|40|warning: format '%d' expects type 'int', but argument 2 has type 'double'|
main.c|9|warning: unused variable 'n'|
main.c|8|warning: unused variable 'y'|
||=== Build finished: 0 errors, 5 warnings ===|
The first three tell you that you're using the wrong format specifier in your "printf()" statements.
--------
I haven't done a thorough analysis of your code, but glancing at the first case, it seems your equations are wrong. I'm rusty with trig, but at least I can show you where your program is going wrong for the first case.
Enter 3 positive integers (separated by 1 space) for the triangle:
1 2 3
Code:
/*
a = 1
b = 2
c = 3
*/
double s = (a + b + c)/2.0;
/*
s = (1 + 2 + 3) / 2 = 3
*/
double area = sqrt(s*(s - a)*(s - b)*(s - c));
/*
area = sqrt(s*(s - a)*(s - b)*(s - c));
= sqrt(3*(3 - 1)*(3 - 2)*(3 - 3));
= sqrt(3*( 2 )*( 1 )*( 0 ));
= sqrt( 0 );
area = 0
*/
printf("This is a scalene triangle.\n");
printf("The area of this triangle is %d.", area);
--------
...and when i hit 'n', the program doesn't end
Code:
printf("Continue? y/n.\n");
scanf("%c", &answer);
while ( answer != 0 );
1. You prompt for input
2. You scan for a character input
3. So why are you checking the user input against zero?