-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircumcalc.c
52 lines (45 loc) · 1.7 KB
/
circumcalc.c
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
#include <stdio.h>
int main()
{
float radius = 0, diameter = 0, circumference = 0, area = 0;
const float pi = 3.14159f;
char state = 'n';
char unit1 = 0, unit2 = 0;
while (state != 'y'){
printf("Input the diameter of the circle (Use a . for the floating point): ");
scanf("%f", &diameter);
printf("\nWhat's the measure unit (i.e. cm)? ");
getchar();
scanf("%c%c", &unit2, &unit1);
while (diameter != 0.0f){{
if (unit1 == '\n'){
printf("\nSubmitted diameter is %f%c, is it correct? ??(y\\n??) ", diameter, unit2);
scanf("%c", &state);}
else {
printf("\nSubmitted diameter is %f%c%c, is it correct? ??(y\\n??) ", diameter, unit2,
unit1);
getchar();
scanf("%c", &state);}}
if (state == 'n'){
diameter = 0.0f;
continue;}
else if (state == 'y'){
radius = diameter/2;
circumference = 2*radius*pi;
area = pi*radius*radius;
if (unit1 == '\n'){
printf("\nThe circumference is %.10f%c.\nThe area is %.10f%c².\n",
circumference, unit2, area, unit2);
return 0;}
else{
printf("\nThe circumference is %.10f%c%c.\nThe area is %.10f%c%c².\n", circumference,
unit2, unit1, area, unit2, unit1);
return 0;}
}
else {
printf("\nInvalid input: please enter either \"y\" or \"n\".\n");
state = 'n';
continue;}
}
}
}