Reputation: 11
I am a beginner in programming and am just starting to write programs that are complex enough where prototypes would be helpful. The problem is when I write my program, compile and run it the functions that are prototyped are blank so none of my cout or cin prompts in the later defined functions appear.
In this code there is only one portion of the switch statement done in which the CubeVol function is prototyped and then later defined.
This code does compile and when it is run it shows the menu. When I type "2" the program ends without couting "length of cubes side" or asking for an input.
if it matters, I'm using Cygwin with gnu g++ compiler and notepad++ to write the code, which is saved as a .C file. I've also tried formatting it as a .cpp
Keep in mind that the mostly blank switch statement is for later when I actually finish the program.
how do i prototype the CubeVol Function Correctly?
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
double CubeVol();
int main()
{ int choice=0;
cout<< " 1. Sphere \n 2. Cube \n 3. Cone \n 4. Cylinder \n 5. Prism \n 6. Exit \n";
cin>> choice;
switch (choice){
case 1:
;
break;
case 2:
CubeVol;
break;
case 3:
;
break;
case 4:
;
break;
case 5:
;
break ;
case 6:
;
;
break;
};
}
double CubeVol ()
{
double side=0.0; double cubev=0.0;
cout<< "length of cubes side";
cin>> side;
cubev= pow(side,3);
return cubev;
}
Upvotes: 0
Views: 64
Reputation: 3324
You are not calling the function CubeVol()
in case 2:
case 2:
std::cout << CubeVol() << "\n"; //call the function and print return value
break;
Also the return value is not being utilized.
Upvotes: 1