Thread: 5-9.c:8: warning: format ‘%f’ expects type ‘float *’, but argument 2 has type ‘double

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    1

    5-9.c:8: warning: format ‘%f’ expects type ‘float *’, but argument 2 has type ‘double

    dont know the problem?? why is there error?
    Code:
    #include <stdio.h>
    float calculateCharge (float x);
    int main (void)
    {
       float hour1,hour2,hour3,totalhour;
       float cost1,cost2,cost3,totalcost;
       printf("Enter hours parked for the three vehicle: ");
       scanf("%f%f%f", hour1,hour2,hour3);
       totalhour=hour1+hour2+hour3;
       cost1=calculateCharge(hour1);
       cost2=calculateCharge(hour2);
       cost3=calculateCharge(hour3);
       printf("Car\tHours\tCharge\n");
       printf("1\t%.2f\t%.2f\n", hour1, cost1);
       printf("2\t%.2f\t%.2f\n", hour2, cost2);
       printf("3\t%.2f\t%.2f\n", hour3, cost3);
       printf("Total\t%.2f\t%.2f\n", totalhour, totalcost);
       return 0;
    }
    float calculateCharge (float x)
    {
       float charge;
       if (x>3){
          charge=((x-3)*.50)+2;
          if (charge>10){
             charge=10;}}
       else {
          charge=2;}
    }

  2. #2
    DESTINY BEN10's Avatar
    Join Date
    Jul 2008
    Location
    in front of my computer
    Posts
    804
    Quote Originally Posted by poyaochuang View Post
    dont know the problem?? why is there error?
    Code:
    #include <stdio.h>
    float calculateCharge (float x);
    int main (void)
    {
       float hour1,hour2,hour3,totalhour;
       float cost1,cost2,cost3,totalcost;
       printf("Enter hours parked for the three vehicle: ");
       scanf("%f%f%f",&hour1,&hour2,&hour3);
       totalhour=hour1+hour2+hour3;
       cost1=calculateCharge(hour1);
       cost2=calculateCharge(hour2);
       cost3=calculateCharge(hour3);
       printf("Car\tHours\tCharge\n");
       printf("1\t%.2f\t%.2f\n", hour1, cost1);
       printf("2\t%.2f\t%.2f\n", hour2, cost2);
       printf("3\t%.2f\t%.2f\n", hour3, cost3);
       printf("Total\t%.2f\t%.2f\n", totalhour, totalcost);
       return 0;
    }
    float calculateCharge (float x)
    {
       float charge;
       if (x>3){
          charge=((x-3)*.50)+2;
          if (charge>10){
             charge=10;}}
       else {
          charge=2;}
    }
    Also there should be a return charge; statement in the calculate() function.
    HOPE YOU UNDERSTAND.......

    By associating with wise people you will become wise yourself
    It's fine to celebrate success but it is more important to heed the lessons of failure
    We've got to put a lot of money into changing behavior


    PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
    IDE- Microsoft Visual Studio 2008 Express Edition

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You need %lf for scanning doubles.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors
    By Rhidian in forum C Programming
    Replies: 10
    Last Post: 04-04-2005, 12:22 PM
  2. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  3. Erros in Utility Header File
    By silk.odyssey in forum C++ Programming
    Replies: 4
    Last Post: 12-22-2003, 06:17 AM
  4. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM