help with arrays and loops

This is a discussion on help with arrays and loops within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> #include <math.h> float calculateCharges(float hours ); // const int NUMBER_OF_CARS= 8; #define NUMBER_OF_CARS 8 int main( void ...

  1. #46
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Code:
    #include <stdio.h>
    #include <math.h>
    
    float calculateCharges(float hours);
    
    //const int NUMBER_OF_CARS= 8;
    #define NUMBER_OF_CARS 8
    
    int main(void)
    {
     int cars[NUMBER_OF_CARS]= {1,2,3,4,5,6,7,8};
     float charges[NUMBER_OF_CARS];
     float hours[NUMBER_OF_CARS];
     float totalHours= 0.0;
     float totalCharges= 0.0;
     int i;
    
     for(i=0; i<NUMBER_OF_CARS; i++)
     {
      printf("Enter the hours for car %d:",i+1); //, cars[i]);
      scanf("%f",&hours[i]);
      totalHours= totalHours + hours[i];
      charges[i]= calculateCharges(hours[i]);
      totalCharges= totalCharges + charges[i];
     }
      printf("\nCars\t\tHours\t\tCharge");
      for(i=0; i<NUMBER_OF_CARS; i++)
     {
      printf("\n");
      printf("%d\t\t%.1f\t\t%.2f", cars[i], hours[i], charges[i]);
     }
      printf("\nTOTAL\t\t%.1f\t\t%.2f", totalHours, totalCharges);
    
     return 0;
    }
    float calculateCharges(float hours)
    {
     float cHours=ceil(hours);
     float charge=0.0;
      if (cHours <= 3.0)
       charge=2.00;
      else if (cHours>3.0 && cHours <= 17.0)
        charge= ((cHours-3.0)*0.5)+2.0; 
      else
        charge= 10.0;
      
      return charge;
    }

    any idea why when i submit it to this site called webcat, i get this error message
    There... I've marked the errors for you....

    Next, you need to stop using online compilers... you have no idea what's behind the website.
    Download a decent free compiler ... smorgasbordet - Pelles C and learn how to use it.

  2. #47
    Registered User
    Join Date
    Nov 2010
    Posts
    35
    thats the compiler we have to submit our work too. ive made the changes and still no luck

  3. #48
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Please post up the revised code you submitted, and paste up the exact message you were given.

    We'll put on our Deerstalking caps and sleuth this mystery out into the open.

    Grab your coat, Watson! The games afoot!

    What compiler are you using, and what is the name of the source file you compiled?
    Last edited by Adak; 11-26-2010 at 11:52 PM.

  4. #49
    Registered User
    Join Date
    Nov 2010
    Posts
    35
    i figured it out, thanks though. preciate all the help!

Page 4 of 4 FirstFirst 1234
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. arrays and loops
    By pmooney12 in forum C Programming
    Replies: 2
    Last Post: 11-22-2010, 09:38 PM
  2. Need help with for loops and arrays
    By Skeeter in forum C Programming
    Replies: 6
    Last Post: 10-23-2009, 03:33 PM
  3. Help with Arrays and For loops
    By Phil- in forum C++ Programming
    Replies: 5
    Last Post: 09-07-2009, 10:34 AM
  4. Help using arrays and loops for math
    By LLINE in forum C++ Programming
    Replies: 3
    Last Post: 06-09-2008, 04:09 AM
  5. help with arrays and loops
    By jdiazj1 in forum C Programming
    Replies: 4
    Last Post: 11-24-2001, 03:28 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21