Hey guys! Very new to C++. Just started taking it this semester.
For some reason my output keeps coming out as [0.000] and I cannot figure out why. Can someone please help me?
** I also tried making r & h a double and it still came out as 0.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
int r = 0;
int h = 0;
const double pi = 3.14159;
cout << "Enter radius: " << endl;
cin >> r;
cout << "Enter height: " << endl;
cin >> h;
double volume = (1/3) * pi * (r * r) * h;
cout << fixed << setprecision(3);
cout << "The volume of the cone is: [" << volume << "]";
return 0;
}
OUTPUT:
Enter radius:
5
Enter height:
10
The volume of the cone is: [0.000]
#include <iostream>
#include <iomanip>
#include <cmath>
usingnamespace std;
int main()
{
int r = 0;
int h = 0;
cout << "Enter radius: "; // INPUT ON ONE LINE IS SOMETIMES BEST
cin >> r;
cout << "Enter height: ";
cin >> h;
double volume = M_PI/3. * (r * r) * h;
cout << fixed << setprecision(3);
cout << "The volume of the cone is: [" << volume << "]\n";
return 0;
}