I've been studying function calling lately. I've written a program to ask for two variables, b and c, from the User, calculate res (resistance), and print the variable res.
I've changed the structure two times, trying to simplify the program so that I can understand the subject of function calling. At one point I had three functions being called from the main function: getVariables, calculate and printOne. Although I was able to build the program without any failures, the variable res was being printed as 0.000000. So, I simplified and kept only the function calculate, and programed the variable res to be printed from the main function. No change. The program still prints 0.000000 for the variable res.
I read through the How-tos of posting. It is stated that I should not post homework. I can't help it. I really enjoy programing at this point, and I really want to know what it is (or what they are) I am not understanding about this program and the output I am receiving versus the output I desire.
Any help is greatly appreciated. If my lesson lies outside of function calling, please let me know. I do want to learn C++. Thanks
Assume that all variables are defined as double.
Note that the program should ask the user to enter the values for the variables b and c
and the program computes and displays the value for the variable res."
double calculate (double b, double c);
int main (void)
printf("\nPlease enter the values for b and c:");
scanf_s("%f %f", &b, &c);
res = calculate(b, c);
printf("\nRes is %f:\n", res);
} // main
This function calculates the formula res using the variable values given by the User for variables b and c.
double calculate (double b, double c)
sum = b + c;
product = b * c;
res = sum / (2 * product);