Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
January 22nd, 2013, 01:36 AM
 theotherstudent
Registered User

Join Date: Jan 2013
Posts: 1
Time spent in forums: 7 m 51 sec
Reputation 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
January 22nd, 2013, 02:02 AM
 Scorpions4ever
Banned ;)

Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
Posts: 9,536
Time spent in forums: 2 Months 3 Days 6 h 44 m 20 sec
Reputation Power: 4106
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.
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

#3
January 22nd, 2013, 03:28 AM
 swapy
Contributing User

Join Date: Feb 2010
Posts: 67
Time spent in forums: 14 h 44 m 39 sec
Reputation 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);

 Viewing: Dev Shed Forums > Programming Languages > C Programming > Homework Help pls