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
|
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
float A, G, V, Q;
const float SENTINEL = Q; //type to stop the loop
float length, width, depth;
char number;
cout << "Enter numbers for Surface Area(A), Girth(G), and Volume(V). To stop the loop, enter Q." << endl;
cin >> number;
while(number != SENTINEL)
if (number == A)
A = 2*length*width + 2*width*depth + 2*length*width;
else if (number == G)
G = 2*(length*width) + depth;
else if (number == V)
V = length * width * depth;
cout << "Continue\n";
cin >> number;
cout << setiosflags(ios::showpoint)
<< setiosflags(ios::fixed)
<< setprecision(2)
<< "The surface area is " << A << endl;
cout << setiosflags(ios::showpoint)
<< setiosflags(ios::fixed)
<< setprecision(2)
<< "The girth+depth is " << G << endl;
cout << setiosflags(ios::showpoint)
<< setiosflags(ios::fixed)
<<setprecision(2)
<< "The volume is " << V << endl;
system("pause");
return 0;
}
|
At the moment, thats the program I created. Apparently it wouldn't do what I want it to do.
1) To calculate the "Surface Area", "Volume", and/or "Girth" of a box.
2) Formulas are: Volume = LWD (Length X Width X Depth)
Surface Area = 2LW + 2WD + 2LD
Girth = 2(L+W) + D
3) Input of the program will be a letter. "V" for volume. "A" for surface area. "G" for girth, and "Q" to stop the loop. (Q is the sentinel). The second part of the input will be a three (float) numbers representing the Length, Width, and Depth respectively.
For example: A 2.0 3.0 4.0 means find the surface area of a box with
Lenght= 2.0, Width= 3.0, and Depth= 4.0
4)For each input, just calculate what is called for, not all three answers. I have to use Nested if-else to control the actions.
5) Use Sentinel controlled while loops to read the data.
6) Libraries: iostream, iomanip (which i already put there)
And the inputs are: A 1.0 2.0 3.0
G 5.0 4.0 3.0
V 2.3 4.9 6.7
A 3.7 4.3 9.6
Q
Everytime I compile & run it, it would let me input "A 1.0 2.0 3.0" but nothing after that.
If anyone can help me, that would be really appreciated. Thank you!