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
109 lines (99 loc) · 1.5 KB
/
three.c
File metadata and controls
109 lines (99 loc) · 1.5 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* Drew French */
/* Takes three user inputs
* and determines whether
* they form a valid triangle,
* the triangle type, and
* makes sure ints were entered.
*/
#include <stdio.h>
void isTriangle(int, int, int);
void triangleType(int, int, int);
void sanitizedInput();
int a;
int b;
int c;
int i;
int main()
{
sanitizedInput();
isTriangle(a, b, c);
triangleType(a, b, c);
return 0;
}
void isTriangle(a, b, c)
{
if(a + b > c && a + c > b && b + c > a)
{
printf("\nThis is a valid triangle.\n");
i = 1;
}
else
{
printf("\nThis is not a valid triangle.\n");
i = 0;
}
}
void triangleType(a, b, c)
{
if(i == 1)
{
if(a == b && b == c)
{
printf("This triangle is equilateral.\n");
}
if((a == b && a != c) || (a == c && a != b) || (b == c && a != b))
{
printf("This triangle is isosceles.\n");
}
if(a != b && b != c)
{
printf("This triangle is scalene.\n");
}
}
}
void sanitizedInput()
{
int v;
do
{
printf("Type a valid length for side a: ");
if(!scanf("%d", &a))
{
printf("Not a valid integer. ");
scanf("%*[^\n]");
v = 0;
}
else
{
v = 1;
}
} while(v == 0);
do
{
printf("Type a valid length for side b: ");
if(!scanf("%d", &b))
{
printf("Not a valid integer.");
scanf("%*[^\n]");
v = 0;
}
else
{
v = 1;
}
} while(v == 0);
do
{
printf("Type a valid length for side c: ");
if(!scanf("%d", &c))
{
printf("Not a valid integer.");
scanf("%*[^\n]");
v = 0;
}
else
{
v = 1;
}
} while(v == 0);
}