Write a c++ program to calcualte the surface area, volume, or "girth + depth" of a box:
the formulas are as follows;
volume = LWD (lengthxwidthxdepth)
surface area= 2lw plus 2wd plus 2ld
girth + depth = 2(l+w) plus d
2. the input of the program will be a letter. V will indicate volume. A is surface area. G is girth plus depth, 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.
3. for each input, just calculate what is called for, not all three ansers. Use NESTED if-elses, or a switch structure to control your actions. THe output should have appropriate labels. Use format to control the appearance of your answers.
4. use sentinel controlled while loops to read the data. The Q for the operation will be the sentinel. THe program should work for any data set, not just the data set below.
5. libraries: iostream, iomanip
input:
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
Output: as specified above
So that's the project and this is what I have so far
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
int V, A, G, Q;
const int SENTINEL = Q; // Cease Loop
float length,width,depth;
V = length*width*depth;
A = 2*(length*width) + 2*(width*depth) + 2*(length*depth);
G = 2*(length*width) + depth;
V = length*width*depth;
A = 2*(length*width) + 2*(width*depth) + 2*(length*depth);
G = 2*(length*width) + depth;
You haven't assigned length, width of depth values. So they probably are storing some garbage value. This is the same for your SENTINEL value. You need to first read in the users number before making the calculations as well as assign q a value. You can do this by using the "cin >> length; " >> is the extraction operator and reads what the user types. This is an overloaded version of the bit wise shift operator and is included in the <iostream> header file you have included. It also says you should use a sentinel loop to read in this data and display appropriate prompts to user explain what is needed of them.
It asks that you only calculate what the user wants you to not all three answers like you are doing. As said you can do this with a switch statement. I would also split your calculations into functions to make the code more modular if you know how to do that.