Need help writing a program

So the purpose of this program is to use functions, nested decisions, and sentinel loops to calculate the surface area, volume, or "Girth + Depth" of a box. I saw many ways to do it on this forum but none of them use functions. The input should be the letter "v" to indicate volume, "a" for surface area, "g" for girth + depth, and "q" to stop the loop (sentinel). Second part of the input should be three (float) numbers representing Length, Width, and Depth.
Please help. This is due in a matter of hours and I would really, really appreciate help. Just a shell even. I know how to do this, but I don't know how to do it using functions.
1
2
3
4
5
6
7
8

float CalculateVolume(float L, float W, float D)
{

  //calculate the volume
  //return the answer
};


Then you call this from your main.
Last edited on
Ahh! Thanks for your reply! Could you please give me an example? I missed a week from school so I'm totally lost. Like an example of calling it from the main.
Also which libraries should I include?
#include <iostream>
using namespace std;


to call it from the main you would just need to write the function and pass it the parameters:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

int main()
{

  float L, W, D;
  float V;

  //get the data from the user using a while loop
  V = CalculateVolume(L, W, D);
  //output the volume.

 //do some other stuff

  return 0;
};
Do I need to put the formula for finding the volume in the function prototype? Like I don't even know how functions really work. Will the function CalculateVolume calculate the volume? Or do I need to give it the formula for doing that when I declare it
Honestly if someone could just write this program for me... I'd be the happiest person alive. And would contribute lots to the forum once I learned my shit, lol.
How could you contribute if you cannot write a very simple program?
Ah but I will be able to when I finish my courses. I'm in a beginning level course.
Here you get some help on how a function works :) http://www.cplusplus.com/doc/tutorial/functions/
that helped a lot actually
So far I have this. The functions are all working. Now I need to create a sentinel controlled while loop and use user input of Volume, Girth + Depth, and Surface Area to determine which function gets used.

#include <iostream>
using namespace std;

float Girth_Depth (float L, float W, float D)
{
float g;
g= 2*(L+W) + D;
return (g);
}

float surface_area (float L, float W, float D)
{
float s;
s= 2*(L*W) + 2*(W*D) + 2*(L*D);
return (s);
}

float CalculateVolume (float L, float W, float D)
{
float v;
v=L*W*D;
return (v);
}



int main ()
{
float L, W, D;
cout << "L=";
cin >> L;
cout << "W=";
cin >> W;
cout << "D=";
cin >> D;

float G;
G = Girth_Depth (L, W, D);
cout << "Volume =" << G;


system ("PAUSE");

return (0);
}
Topic archived. No new replies allowed.