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
58 lines (48 loc) · 1.24 KB
/
three.c
File metadata and controls
58 lines (48 loc) · 1.24 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
/* Jared Wasserman -- three.c */
/* This program takes three integers (for the sides of a traingle) and returns wether or not they form a valid triangle and what kind of triangle they form*/
#include <stdio.h>
int sanitizedInput(char);
int isTriangle(int,int,int);
void triangleType(int,int,int);
int main(){
int a = sanitizedInput('1');
while(getchar()!='\n');
int b = sanitizedInput('2');
while(getchar()!='\n');
int c = sanitizedInput('3');
if(isTriangle(a,b,c)){
triangleType(a,b,c);
}
return 0;
}
int sanitizedInput(char character){
int returnValue;
int input;
do{
printf("Please enter value for side %c: ",character);
returnValue = scanf("%d",&input);
if(returnValue==0){
printf("Invalid Input. ");
while(getchar()!='\n');
}
}while(returnValue==0);
return input;
}
int isTriangle(int a, int b, int c){
if(a>(b+c)||b>(a+c)||c>(b+a)){
printf("%d,%d,%d: do not form a valid triangle.\n",a,b,c);
return 0;
}else{
printf("%d,%d,%d: forms a valid triangle.\n",a,b,c);
return 1;
}
}
void triangleType(int a, int b, int c){
if(a==b&&b==c){
printf("%d,%d,%d: is equilateral.\n",a,b,c);
}else if(a==b||b==c||c==a){
printf("%d,%d,%d: is isocles.\n",a,b,c);
}else{
printf("%d,%d,%d: is scalene.\n",a,b,c);
}
}