I have been trying to figure out the proper use of functions. I sort of understand them, but then again, I sort of don't. I know my calling of them in main is just a disaster, and as simple as this program sounds, it is really frustrating me.
I'd appreciate any help.
The purpose: takes two inputs from the user (voltage and resistance) in a function and returns the amp value (voltage / resistance *1000) and then prints it in main. There is also error checking that needs to be done to make sure the input values are greater than zero. Ugh.
Code:
#include <stdio.h>
float input(float volts, float resistance);
float current(float value);
void display(void);
float input(float volts, float resistance)
{
float value, volts, resist;
printf("Enter a value for voltage and resistance, separated by a space: ");
scanf("%f %f", &volts, &resist);
value = (volts/resist);
return value;
}
float current(float value)
{
float current;
current=value*1000;
return current;
}
void display(void)
{
printf("The current is %f", current);
}
int main(void)
{
float current;
curent=current(value);
display();
return 0;
}
~
I am sure I have wrong floats being used and saved into functions..right now I feel as if I have absolutely no clue what I am doing. It sounded so simple when I read it a few days ago, but now =(