c++ - Warning converting to `int' from `double' -


hey 1 of first things i've ever coded. wondering how might fix error. trying research can't find helpful in fixing it.

#include <iostream>            // needed cin , cout #include <cmath> #include <csmath> using namespace std;  /************************************ *     defines *************************************/ #define  pi  3.14159  /************************************* *     function prototype *************************************/  int main() { //surface , volume  float radius;  float height; float surfacearea; float volume; int pi = 3.14159  //get radius cout << "enter radius: "; cin >> (float)radius;  //get height cout << "enter height: "; cin >> height;  //get surfacearea surfacearea = 2(pi*radius^2)+2(pi*radius)* height; cout << "the surfacearea is: " << surfacearea;  //get volume volume = (pi*radius)^2*height; cout << "the volume is: " << volume << endl;      system ("pause"); return 0;  } 

change int double pi, because pi floating point number, which, stated in comments, c++'s default floating point numbers. unless there particular reason use float, use double floating-point numbers.

double pi = 3.14159; 

and warning go away.

also, don't have cast input float, simply:

cin >> radius; 

additionally, @ least, change radius^2 radius*radius.

but better yet, avoid ^ altogether , use std::pow, example of can found here.

additionally, don't need #define pi 3.14159 because never use it, , try define pi in main().


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -