-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathex03.cpp
48 lines (41 loc) · 1.01 KB
/
ex03.cpp
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
#include <iostream>
struct box
{
char maker[40];
float height;
float width;
float length;
float volume;
};
void displayBox(box b);
void setVolume(box * b);
int main()
{
int choice = 0;
box myBox {"MyBox", 10, 10, 10, 0};
std::cout << "MyBox: \n1. Display dimensions \n2. Calculate volume\n";
std::cout << "\nSelect an option: ";
while (std::cin >> choice) {
switch (choice)
{
case 1:
displayBox(myBox);
break;
case 2:
setVolume(&myBox);
std::cout << "Volume: " << myBox.volume << std::endl;
break;
}
std::cout << "\nSelect an option: ";
}
}
void displayBox(box b)
{
std::cout << "\nHeight: " << b.height << "\nWidth: " << b.width;
std::cout << "\nLength: " << b.length << "\nVolume: " << b.volume;
std::cout << "\nMaker: " << b.maker << std::endl;
}
void setVolume(box * b)
{
b->volume = (b->height * b->width * b->length);
}