forked from CPRF-Session2/Assignment5
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththree.c
More file actions
64 lines (56 loc) · 1.34 KB
/
Copy paththree.c
File metadata and controls
64 lines (56 loc) · 1.34 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* Mariposa Lee, using 3 functions to check a triangle type based on user input integers for side lengths*/
#include <stdio.h>
#include <math.h>
int isTriangle(int num1, int num2, int num3) {
int q;
if ((num1+num2 >= num3) && (num2+num3 >= num1) && (num1+num3 >= num2)){
q=1;}
else {q=0;}
return q;
}
int triangleType(int num1, int num2, int num3) {
int h;
if ((num1==num2) && (num1==num3)){
h= 1;}
else if (
((num1==num2) && (num1!=num3)) ||
((num2==num3) && (num2!=num1)) ||
((num1==num3) && (num1!=num2)) )
{
h = 2;}
else if ((num1!=num2) && (num1!=num3) && (num2!=num3))
{ h= 0;}
else {h=3;}
return h;
}
int sanitizedInput(int num) {
printf("Please enter a number.\n");
scanf("%d", &num);
while (getchar()!='\n') {
printf("Invalid number. Try again.\n");
scanf("%d", &num);
}
return num;
}
int main () {
int a,b,c;
int q,w,e;
q=sanitizedInput(a);
w=sanitizedInput(b);
e=sanitizedInput(c);
int valid;
valid =isTriangle(q, w, e);
if (valid == 1) {
printf("The triangle is valid.\n"); /*Only prints triangle type if triangle is valid.*/
int type;
type= triangleType(q, w, e);
if (type == 1) {
printf("The triangle is equilateral.\n");}
else if (type==2) {
printf("The triangle is isoceles.\n");}
else if (type ==0) {
printf("The triangle is scalene.\n");}
}
else { printf("The triangle is not valid.\n");}
return 0;
}