-
Notifications
You must be signed in to change notification settings - Fork 18
/
Quiz 6.c
135 lines (116 loc) · 2.55 KB
/
Quiz 6.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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*Programmers: Isaah Santos, Chase Singhofen, Brandt Barry
Date: 12-1-16
Specifications: Quiz 6*/
#include<stdio.h>
#include<stdlib.h>
double circleInput()
{
double radius;
printf("Please enter the radius of your circle:\n");
scanf_s("%lf", &radius);
return radius;
}
double circleArea(double a)
{
double area;
area = 3.14 * (a * a);
return area;
}
double circleCircum(double a)
{
double circum;
circum = 2 * 3.14 * a;
return circum;
}
void displayCircle(double a, double b)
{
printf("The area of your circle is %.2lf\nThe circumference of your circle is %.2lf.\n", a, b);
}
double triangleBaseInput()
{
double base;
printf("Please enter the base of the triangle:\n");
scanf_s("%lf", &base);
return base;
}
double triangleHtInput()
{
double height;
printf("Please enter the height of the triangle:\n");
scanf_s("%lf", &height);
return height;
}
double triangleArea(double a, double b)
{
double tArea;
tArea = (a * b) *0.5;
return tArea;
}
void displayResults(double a)
{
printf("The area of your triangle is %.2lf\n", a);
}
double sqInput()
{
double length;
printf("Please enter the length of the side of your square:\n");
scanf_s("%lf", &length);
return length;
}
double sqArea(double a)
{
double area;
area = a * a;
return area;
}
double sqPeri(double a)
{
double perimeter;
perimeter = a * 4;
return perimeter;
}
void displayArea(double a, double b)
{
printf("The area of your square is %.2lf.\nThe perimeter is %.2lf.\n", a, b);
}
main()
{
int selection = 0;
double a = 0.0, b = 0.0, area = 0.0, circum = 0.0, cnum1 = 0.0, cnum2 = 0.0, cnum3 = 0.0, tnum1 = 0.0, tnum2 = 0.0, tnum3 = 0.0, snum1 = 0.0, snum2 = 0.0, snum3 = 0.0;
do
{
printf("Select an option from the following list:\n");
printf("1. Circle\n2. Triangle\n3. Square\n4. Exit\n");
scanf_s("%i", &selection);
if (selection == 1)
{
cnum1 = circleInput();
cnum2 = circleArea(cnum1);
cnum3 = circleCircum(cnum1);
displayCircle(cnum2, cnum3);
}
else if (selection == 2)
{
tnum1 = triangleBaseInput();
tnum2 = triangleHtInput();
tnum3 = triangleArea(tnum1, tnum2);
displayResults(tnum3);
}
else if (selection == 3)
{
snum1 = sqInput();
snum2 = sqArea(snum1);
snum3 = sqPeri(snum1);
displayArea(snum2, snum3);
}
else if (selection == 4)
{
printf("Thank you for using this program!\n");
}
/*else
{
printf("That is not an option!\n");
}*/
} while (selection != 4);
system("pause");
}