[Solved] Trying to create functions with simple equations inside [closed]


There are no objects here that I can see. You’re using C++ as “a better C”.

It’s been a long time since I’ve written C or C++, but I think you want something more like this. I’ve taken the meat out of the main to emphasize my point:

#include <iostream>
#include <cmath>

using namespace std;

static const double    PI = 3.14159;  // surely you can do better than six digits

double topSurfaceArea(double r, double h) { return 2.0*PI*r*(r+h); } 
double lateralSurfaceArea(double r, double h) { return 2.0*PI*r*h; }
double volume(double r, double h) { return PI*r*r*h; }  // your formula was clearly wrong.

int main() { // removed body for simplicity }

3

solved Trying to create functions with simple equations inside [closed]