### Problem with my program

I recently made a program which calculates pi formulas and I'm having trouble calculating the volume of a cone, every time it receives input, it still print out a zero. Is there any way I could solve this?

And as a side question, is there anything I could do to make it faster?

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176`` `````` (#include "stdafx.h" #include #include using namespace std; int main(); void chooser(); const double pi = 3.14159; void circleCircum() { char choose; do { cout << "Enter radius" << endl; int radius = 0; cin >> radius; int circum = pi * ( 2 * radius); cout << "Circumference is: " << circum << endl; cout << "Do you want to do this again? (y/n)" << endl; cin >> choose; }while (choose == 'y'); chooser(); } void surfaceCylinder() { char choose; do { cout << "Enter radius" << endl; int radius = 0; cin >> radius; cout << "Enter height" << endl; int height = 0; cin >> height; int surface = (2 * pi * (radius * radius)) + (2 * pi * radius * height); cout << "Surface Area is:" << surface << endl; cout << "Do you want to do this again? (y/n)" << endl; cin >> choose; }while (choose == 'y'); chooser(); } void volumeCylinder() { char choose; do { cout << "Enter radius" << endl; int radius = 0; cin >> radius; cout << "Enter height" << endl; int height = 0; cin >> height; int volume = pi * (radius * radius) * height; cout << "Volume is: " << volume << endl; cout << "Do you want to do this again? (y/n)" << endl; cin >> choose; }while (choose == 'y'); chooser(); } void surfaceCone() { char choose; do { cout << "Enter radius" << endl; int radius = 0; cin >> radius; cout << "Enter slope" << endl; int slope = 0; cin >> slope; int surface = (pi * radius * slope) + (pi * (radius * radius)); cout << "Surface Area is:" << surface << endl; cout << "Do you want to do this again? (y/n)" << endl; cin >> choose; }while (choose == 'y'); chooser(); } void volumeCone() { char choose; do { cout << "Enter radius" << endl; int radius = 0; cin >> radius; cout << "Enter height" << endl; int height = 0; cin >> height; int volume = (1/3) * pi * (radius * radius) * height; cout << "Volume is:" << volume << endl; cout << "Do you want to do this again? (y/n)" << endl; cin >> choose; }while (choose == 'y'); chooser(); } void chooser() { cout << "Command characters: " << endl; cout << "Circumference of a circle: c" << endl << "Surface Area of a cylinder: s" << endl << "Volume of a cylinder: v" << endl << "Surface Area of a cone: u" << endl; cout << "Volume of a cone: o" << endl << "Exit program: x" << endl; char choose; cin >> choose; switch (choose) { case 'c': circleCircum(); break; case 's': surfaceCylinder(); break; case 'v': volumeCylinder(); break; case 'u': surfaceCone(); break; case 'o': volumeCone(); break; case 'x': return; break; default: cout << "You did not enter a valid charcter" << endl; chooser(); break; } } int main() { cout << "Hello, this is the Pi equations calculator alpha 0.3" << endl; chooser(); cout << "Bye" << endl; return 0; } ``````
The problem is that you are using ints, when you should use floats or doubles. For ints 1/3=0
I tried that and it didn't work
Check if you get the same answer. Igore the static_cast, I just did that to suppress a warning. Note how I wrote 1/3 as 1./3., and all variables are doubles, not ints
 ``123456789101112131415`` ``````#include using namespace std; const double pi = 3.14159; int main() { int volume,radius=1,height=1; volume = static_cast((1/3) * pi * (radius * radius) * height); cout<
Topic archived. No new replies allowed.