#1
  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. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,648
    Rep Power
    4248
    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

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. 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);

IMN logo majestic logo threadwatch logo seochat tools logo