1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Jan 2013
Posts
1
Rep Power
0

#### Homework Help pls

I need a bit of homework help for you programmers out there. I need to write a program for pelles ide to calculate current and power in a resistor what I have so far is

int main (void)
{
double resistance; /*Stores resisitance entered by user*/
double voltage; /*Stores voltage entered by user*/
double current; /*Stores current after calculation*/
double power; /*Stores power dissipation after calculation*/
double Watts; /*Stores current after calculation*/
double I; /*Value for power*/

printf("enter resistance: ohms");
scanf("%.3f, &resistance ohms");
printf("enter voltage: volts");
scanf("%.3f, *voltage volts");

/*Calculate current as current equals voltage divided by resistance*/
current = voltage / resistance;

/*Calculate power dissipation as power equals voltage times current*/
power = voltage * current;

/*Output voltage and resistance*/

printf("The current of a circuit with voltage and resistance %.3f is %.3f\n", Watts);
printf("The power in a circuit with voltage and current \$.3f is %.3f\n", I);
return (0);
}

but I get errors
I:\School Work\resistor\resistor\resistor.c(30): warning #2233: Insufficient number of arguments to 'printf' according to the format string.
I:\School Work\resistor\resistor\resistor.c(14): warning #2116: Local 'Watts' is used without being initialized.
I:\School Work\resistor\resistor\resistor.c(15): warning #2116: Local 'I' is used without being initialized.

how do I fix?
2. You should learn to understand what your compiler is telling you. For instance:
"I:\School Work\resistor\resistor\resistor.c(30): warning #2233: Insufficient number of arguments to 'printf' according to the format string."
Here, when it says:
"I:\School Work\resistor\resistor\resistor.c(30)"
it is telling you that the error is in resistor.c close to line number 30.
Next, the actual error message:
"Insufficient number of arguments to 'printf' according to the format string."
What this is telling you is that in your printf() format string, you have multiple % arguments (you have two %.3f in there), but you don't have enough arguments after that (you only have Watts, which is a single argument).

Similarly, read the other error messages. They explain EXACTLY what mistakes you made and approximately where you made them.
3. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Feb 2010
Posts
68
Rep Power
0
printf("The current of a circuit with voltage and resistance %.3f is %.3f\n", Watts);
printf("The power in a circuit with voltage and current \$.3f is %.3f\n", I);

in both lines u used 2 format specifiers but supplied only one value ... u need to supply 2 values....

correction would be:
printf("The current of a circuit with voltage and resistance %.3f is %.3f\n", resistance,Watts);
printf("The power in a circuit with voltage and current \$.3f is %.3f\n", I,Watts);