I am writing a BMI calculation program, but i keep running into some problems.
I cant get the program to call another function further in the code. no matter what value i give it.
Could someone help this noob out?
Thanks in advance, im sure the answer is quite easy
void geslacht(char M, char V)
{
float geslacht; // <--- Bels to use a "double".
cin >> geslacht; // <--- Expects a number. A floating point number.
if (geslacht = M) // Trying to set a floating point number equal to a "chat". Not possible.
BMIM();
if (geslacht = V)
BMIV();
}
"=" means to set and "==" means to compare. Even as "==" you are comparing a floating point number to a "char".
I think what you are looking for is:
1 2 3 4 5 6 7 8 9 10 11 12
void geslacht(char M, char V)
{
char geslacht;
cin >> geslacht;
if (geslacht == 'M' || geslacht == 'm')
BMIM();
if (geslacht = V)
BMIV();
}
You will need to fix the other if statement, but that should solve the problem and call the right function.
The other problem I see is that line 13 in "main" calls the function with no parameters, but the function is expecting 2 parameters.
The prototype, Line 6 must match the function on line 73 and the function call needs to match the function definition, but in the function call only the names are needed not the type.
Note: Notice the use of blank lines and how it makes the code easier to read. The first benefit is to you and the second benefit is to those who have to read your code. The easier it is to read the quicker the response.
I completely understand what Handy Andy was saying now and the problem is solved.
As you can say im new to programming and wasnt sure what parameters were and how to use everything.
Thanks, just had a quick look at the site and it explains a lot in an easy way. thanks for te tip!
the code i came up with is:
Right now im looking to make it a bit more compact.
maybe make another function call, but not sure how or where.
I would like to put a value back to "main" not sure why but just to try somethings.
Another shorter way of initializing number variables, since C++11 on, double lengte{}. The empty {}, the uniform initialize, will set the variable to the type of zero based on the variables type. In this case it would be "0.0". An "int" would be zero and a "char" would be "\0".