Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

what is the problem with this code below?

+1 vote
asked Jul 22, 2018 by Kenneth Otieno Ouko (180 points)
//calculate volume and surface area of a cone using c++ function programe
#include<iostream>
#include<cmath>
using namespace std;
double vcone(float r,float h);
double scone(float r,float h);
int main(){
float r,h;
cout<<"enter the values of r,and h:"<<endl;
cin>>r>>h;
cout<<"volume of a cone is:"<<vcone<<endl;
cout<<"surface area of a cone is:"<<scone<<endl;
return 0;
}
double vcone(float r,float h){
    const float pi=3.142;
    float volume;
    volume=1/3.0*pi*pow(r,2)*h;
    return volume;
}
double scone(float r,float h){
    const float pi=3.142;
    float surfacacearea;
    surfacacearea=pi*r*(r+sqrt(pow(h,2)+pow(r,2)));
    return surfacacearea;
}

2 Answers

0 votes
answered Jul 23, 2018 by anonymous
header file for math function is wrong. it is #include<math.h> not #include<cmath>
commented Jul 23, 2018 by Kenneth Otieno Ouko (180 points)
Ok, but it gives constant values of vcone and scone for different r and h
0 votes
answered Jul 25, 2018 by Shreyas Ghuge (140 points)

When you call the functions in main ie vcone and scone you should also pass the radius and height in the function call. 

cout<<"volume of a cone is:"<<vcone(r, h)<<endl;
cout<<"surface area of a cone is:"<<scone(r, h)<<endl;

like so! 

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...