Hi every one I'm new to this forum and would greatly appreciate some help with a formula.
I am currently doing a class at home on c++. I have to write a program for a farmer so he can calculate how much fertilizer to add to his tanker according to the size of his field in hectares and how much is currently in the tank. Also the fertilizer mixture ratio is 3 litres of water to 1 litre of fertilizer.
The fertilizer is sprayed at a rate of 2000 litres per hectare.
There is only one area I am having trouble with and that is the calculation of fertilizer currently in the tank. The farmer users a dip stick whitch measures the level of fertilizer in millimeters. the tanks diameter is 2.5 meters and 4 meters long.
I believe I have found the correct formula for this calculation (which I don't fully understand, I was never very good with maths in high school)
here is the formula: A = pi*r^2/2 - r^2*arcsin(1-h/r) - (r-h)*sqrt(h(2r-h))
A = area r = radius h = height
My problem is I don't really know how to implement the above formular into c++ code I have from what I have researched I have tried to use the math.h to gain access to the functions I need. My code is below.
#include <cstdlib>
#include <iostream>
#include <math.h>
#define pi 3.14159265
using namespace std;
int main()
{
double area = 0;
//height in millimeters
double h = 5;
//radius
double r = 1.25;
area = pi*pow(r,2)/2 - pow(r,2)*asin(1-h/r)-(r-h)sqrt(h(2r-3));
cout << "the area is: " << area << endl;
system("PAUSE");
return 0;
}
and here are the errors I get on compile
line 16: expected ; before "sqrt"
line 16: invalid suffix "r" on interger constant
area = pi*pow(r,2)/2 - pow(r,2)*asin(1-h/r)-(r-h)sqrt(h(2r-3));
cout << "the area is: " << area << endl;
If look, where you have sqrt(h(2r-3) you forgot the * symbol between that and the (r-h) that came before it.
area = pi*pow(r,2)/2 - pow(r,2)*asin(1-h/r)-(r-h)*sqrt(h(2r-3));
EDIT: Missed the second error. You need to declare that two things are being multiplied I believe, so where you have (2r - 3) the compiler is confused as to what 2r is. You need to do (2 * r - 3)
Final should look like this: area = pi*pow(r,2)/2 - pow(r,2)*asin(1-h/r)-(r-h)*sqrt(h(2*r-3))
Also, it's supposed to be h*(2*r-3), not h(2*r-3). You can slightly improve the expression by moving pow(r,2) as a common factor of the subtraction, and probably also by replacing it with r*r.