The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Homework Help pls
Discuss Homework Help pls in the C Programming forum on Dev Shed. Homework Help pls C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 22nd, 2013, 12:36 AM
|
|
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?
|

January 22nd, 2013, 01:02 AM
|
 |
Banned ;)
|
|
Join Date: Nov 2001
Location: Woodland Hills, Los Angeles County, California, USA
|
|
|
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
|

January 22nd, 2013, 02:28 AM
|
|
Contributing User
|
|
Join Date: Feb 2010
Posts: 66
Time spent in forums: 14 h 4 m
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);
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|