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
|
#include <iostream>
#include <iomanip>
using namespace std;
const int SENTINEL = 'Q'; //type to stop the loop
int main()
{
float A, G, V;
float length, width, depth;
char number;
cout << setiosflags(ios::showpoint)
<< setiosflags(ios::fixed)
<< setprecision(2);
cout << "Enter numbers for Surface Area(A), Girth(G), and Volume(V). To stop the loop, enter Q." << endl;
cin >> number;
while(number != SENTINEL) //sentinel controlled while loop
{
float length, width, depth;
switch (number)
{
case 'A':
A = 2*length*width + 2*width*depth + 2*length*width;
cout << "The surface area is " << A << endl;
break;
case 'G':
G = 2*length*width + depth;
cout << "The girth+depth is " << G << endl;
break;
case 'V':
V = length*width*depth;
cout << "The volume is " << V << endl;
break;
}
cin >> number;
}
system("pause");
return 0;
}
|
At the moment, that is my program I created. I'm supposed to find the surface area, girth, and volume using the formulas given:
Volume = LWD (length X width X Depth)
Surface Area = 2LW plus 2WD plus 2LD
Girth = 2(L plus W) plus D
*input of the program will be a letter. (example: "V" will indicate volume, "A" for surface area, and "G" for girth) & Q is the sentinel (to stop loop).
*Second part of the input will be a three (float) numbers representing length, width, and depth respectively.
For example: A 2.0 3.0 4.0 means "Find the surface area of box with length = 2.0, width = 3.0, and depth = 4.0.
I'm using a switch structure to control the actions.
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
Enter numbers for Surface Area(A), Girth(G), and Volume(V). To stop the loop, en
ter Q.
A 1.0 2.0 3.0
The surface area is 0.00
G 5.0 4.0 3.0
The girth+depth is 0.00
V 2.3 4.9 6.7
The volume is 0.00
A 3.7 4.3 9.6
The surface area is 0.00
Q
Press any key to continue . . . |
^^ that is my output. So the problem is for me is that it comes out as "0.00" for all outputs.
Is there anyway to fix that?