I am finding it hard to debug this line of code. The proper result should be 14,130 but I am getting 10597.5 instead when the input is 15 for area of a sphere. Below is the code:
// HW1, Q2
#include <iostream>
using namespace std;
int main() {
// declare variables for radius, length and formulas.
int user_nbr;
double pi, sqr_area, circ_area, sphr_area;
pi = 3.14;
cout<<"Hi, enter an integer: "<<endl;
// write in user data into declared variables
cin >> user_nbr, sqr_len, circ_rad, sphr_rad;
sqr_area = user_nbr * user_nbr;
circ_area = pi * user_nbr * user_nbr;
sphr_area = (4/3) * pi * user_nbr * user_nbr * user_nbr;
// displays answers to user
cout<<"\nThe area of a square with length "
<<user_nbr<<" is "<<sqr_area<<". The area "
<<"of a circle with radius "<<user_nbr
<<" is "<<circ_area<<". Lastly, the area "
<<"of a sphere with radius "<<user_nbr
<<" is "<<sphr_area<<".";
return 0;
}
I am new to C++ so I am attempting to understand the operators and their workings. I know it's () */% +- in that order of precedence.