Help my program is giving a problem

This is a discussion on Help my program is giving a problem within the C Programming forums, part of the General Programming Boards category; Thx very much it works like a charm do u know of a better way for the time part of ...

  1. #16
    Registered User
    Join Date
    Feb 2010
    Posts
    36
    Thx very much it works like a charm do u know of a better way for the time part of my program cause im gonna need something easier to use and i read up on time.h that sounds like it mostly gives me the current time on my pc and not something that makes the users input their time to manipulate it. Its necessary cause im gonna add on a tax function ni my program for different parking times.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    
    char vehicle[5];
    int car;
    int truck;
    int hrsn; //Hour the vehicle entered the parking lot
    int minn; //Minute the vehicle came in the parking lot
    int hrso; //Hour the vehicle left the parking lot
    int mino; //Minute the vehivle left the parking lot
    int hr; //final hour
    int min; //final minute
    hrsn=0;
    hrso=0;
    minn=0;
    mino=0;
    hr=0;
    min=0;
    int main()
    
    {
    
    
    printf("Where you driving a car or truck?\n");
    scanf("%s", &vehicle );
    
    while( strcmp( vehicle, "truck" ) != 0 && strcmp( vehicle, "car" ) != 0 )
    {
        printf("Please input the words Car or Truck: ");
        scanf("%s",&vehicle);
    }
    
    
    printf("What Hour did the %s enter the lot? (0-23)\n", vehicle);
    scanf("%d",&hrsn);
    while((hrsn<0 || hrsn>23))
    {
        printf("\a\a\a Please Input Value from 0-23!\n");
        scanf("%d",& hrsn);
    }
    
    {
        printf("What Minute did the %s enter the lot? (0-59)\n", vehicle);
        scanf("%d",& minn);
    }
    while((minn<0 || minn>59))
    {
        printf("\a\a\a Please Enter Correct Minute Between 0-59!\n");
        scanf("%d",& minn);
    }
    
    {
        printf("What Hour did the %s leave the lot? (0-23)\n", vehicle);
        scanf("%d",& hrso);
    }
    while((hrso<0 || hrso>23))
    {
        printf("\a\a\a Please Enter the Correct Time Between 0-23!\n");
        scanf("%d",& hrso);
    }
    
    {
        printf("What Minute did the %s leave the lot? (0-59)\n", vehicle);
        scanf("%d",& mino);
    }
    while(mino<0 || mino>59)
    {
        printf("\a\a\a PLease Enter the Correct time between 0-59!\n");
        scanf("%d",& mino);
    }
    
    {
    if (hrsn < (hrso - 1) && minn > mino)
    {
    hrso = hrso - 1;
    mino = mino + 60;
    }
    if (mino - minn > 1 && mino - minn < 30)
    {
    mino = minn+30;
    }
    
    else if (mino - minn > 30 && mino - minn < 60)
    {
    mino = minn + 60;
    }
    
    else
    {
    mino = minn + 00;
    }
    
    
    hr = (hrso-hrsn);
    min = (mino - minn);
    
    printf("Time in %d:%d\n", hrsn, minn);
    
    printf("Parking Time %d hours:%d minutes\n", hr, min);
    
    }
    
    return 0;
    
    }

  2. #17
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    What would be a time format that is "easier to use"?

    Post up an example of what you want for timed entry. The logic is not a problem, but reading your mind is a sure flop.

  3. #18
    Registered User
    Join Date
    Feb 2010
    Posts
    36
    time in 2:45pm time out : 3:50pmsomething like that cause i would need to minus the time in form the time out

  4. #19
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by zangetsu View Post
    time in 2:45pm time out : 3:50pmsomething like that cause i would need to minus the time in form the time out
    So you subtract hours out, from hours in, and then you need a bit of logic:

    Code:
    if(minute_in < minute_out) {
      minutes_used = 60 - (minute_out - minute_in) 
      //minutes_used = 60 - 5
      //minutes_used = 55 minutes
    }
    else if(minute_in > minute_out)
      minutes_used = (60 - minute_out) + minute_in
    else
      minutes_used = 0; //minutes_in equals minutes_out
    Give that logic a shot. I don't see a way to make your time format somehow make your time calculations, any easier. There are still just 60 minutes in an hour, and 24 hours in a day, so the above type of logic, is still going to be needed.

  5. #20
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Adak View Post
    What would be a time format that is "easier to use"?

    Post up an example of what you want for timed entry. The logic is not a problem, but reading your mind is a sure flop.
    Keep the time internally in seconds... convert to hours:min:sec for display purposes only.
    Then it's just a math problem...

  6. #21
    Registered User
    Join Date
    Feb 2010
    Posts
    36
    Thx i tried it an it works but the problem im trying to fix is that when minutes in > minutes out it gives mi a negative number in the end like "1 hour:-5 minutes"

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    #include <math.h>
    
    char vehicle[5];
    int car;
    int truck;
    int hrsn; //Hour the vehicle entered the parking lot
    int minn; //Minute the vehicle came in the parking lot
    int hrso; //Hour the vehicle left the parking lot
    int mino; //Minute the vehivle left the parking lot
    int hr; //final hour
    int min; //final minute
    int minutes_max;//60 minutes
    int hours_max;//24 hours
    hrsn=0;
    hrso=0;
    minn=0;
    mino=0;
    hr=0;
    min=0;
    int main()
    
    {
    
    
    printf("Where you driving a car or truck?\n");
    scanf("%s", &vehicle );
    
    while( strcmp( vehicle, "truck" ) != 0 && strcmp( vehicle, "car" ) != 0 )
    {
        printf("Please input the words Car or Truck: ");
        scanf("%s",&vehicle);
    }
    
    
    printf("What Hour did the %s enter the lot? (0-23)\n", vehicle);
    scanf("%d",&hrsn);
    while((hrsn<0 || hrsn>23))
    {
        printf("\a\a\a Please Input Value from 0-23!\n");
        scanf("%d",& hrsn);
    }
    
    {
        printf("What Minute did the %s enter the lot? (0-59)\n", vehicle);
        scanf("%d",& minn);
    }
    while((minn<0 || minn>59))
    {
        printf("\a\a\a Please Enter Correct Minute Between 0-59!\n");
        scanf("%d",& minn);
    }
    
    {
        printf("What Hour did the %s leave the lot? (0-23)\n", vehicle);
        scanf("%d",& hrso);
    }
    while((hrso<0 || hrso>23))
    {
        printf("\a\a\a Please Enter the Correct Time Between 0-23!\n");
        scanf("%d",& hrso);
    }
    
    {
        printf("What Minute did the %s leave the lot? (0-59)\n", vehicle);
        scanf("%d",& mino);
    }
    while(mino<0 || mino>59)
    {
        printf("\a\a\a PLease Enter the Correct time between 0-59!\n");
        scanf("%d",& mino);
    }
    
    {
    if(minn < mino)
    {
      minutes_max = 60 - (mino - minn);
      //minutes_max = 60 - 5
      //minutes_max = 55 minutes
    }
    else if(minn > mino)
      minutes_max = (60 - minn) + (mino - 60);
    
    else
      minutes_max = 0; //minutes_in equals minutes_out
    
    
    if (hrsn < hrso)
    {
        hours_max = 24 - (hrso - hrsn);
    }
    
    else if (hrsn > hrso)
    hours_max = (24 - hrso) + minn;
    else
    hours_max = 0;
    
    
    hours_max = (hrso - hrsn);
    minutes_max = (mino - minn);
    
    printf("Time in %d:%d\n", hrsn, minn);
    printf("Time out %d:%d\n", hrso, mino);
    printf("Parking Time:  %d:%d \n", hours_max, minutes_max);
    
    }
    
    return 0;
    
    }

  7. #22
    Registered User
    Join Date
    Feb 2010
    Posts
    36
    i revised cause im trying to make it take off an hour from it its really confusing my brain

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    #include <math.h>
    
    char vehicle[5];
    int car;
    int truck;
    int hrsn; //Hour the vehicle entered the parking lot
    int minn; //Minute the vehicle came in the parking lot
    int hrso; //Hour the vehicle left the parking lot
    int mino; //Minute the vehicle left the parking lot
    int hr; //final hour
    int min; //final minute
    int minutes_max;//60 minutes
    int hours_max;//24 hours
    hrsn=0;
    hrso=0;
    minn=0;
    mino=0;
    hr=0;
    min=0;
    minutes_max=0;
    hours_max=0;
    
    int main()
    
    {
    
    
    printf("Where you driving a car or truck?\n");
    scanf("%s", &vehicle );
    
    while( strcmp( vehicle, "truck" ) != 0 && strcmp( vehicle, "car" ) != 0 )
    {
        printf("Please input the words Car or Truck: ");
        scanf("%s",&vehicle);
    }
    
    
    printf("What Hour did the %s enter the lot? (0-23)\n", vehicle);
    scanf("%d",&hrsn);
    while((hrsn<0 || hrsn>23))
    {
        printf("\a\a\a Please Input Value from 0-23!\n");
        scanf("%d",& hrsn);
    }
    
    {
        printf("What Minute did the %s enter the lot? (0-59)\n", vehicle);
        scanf("%d",& minn);
    }
    while((minn<0 || minn>59))
    {
        printf("\a\a\a Please Enter Correct Minute Between 0-59!\n");
        scanf("%d",& minn);
    }
    
    {
        printf("What Hour did the %s leave the lot? (0-23)\n", vehicle);
        scanf("%d",& hrso);
    }
    while((hrso<0 || hrso>23))
    {
        printf("\a\a\a Please Enter the Correct Time Between 0-23!\n");
        scanf("%d",& hrso);
    }
    
    {
        printf("What Minute did the %s leave the lot? (0-59)\n", vehicle);
        scanf("%d",& mino);
    }
    while(mino<0 || mino>59)
    {
        printf("\a\a\a PLease Enter the Correct time between 0-59!\n");
        scanf("%d",& mino);
    }
    
    {
    if(minn < mino)
    {
      minutes_max = 60 - (mino - minn);
      //minutes_max = 60 - 5
      //minutes_max = 55 minutes
    }
    else if(minn > mino)
    {
         minutes_max = (60 - minn) + mino;
         hours_max = hours_max-1;
    }
    
    else
      minutes_max = 0; //minutes_in equals minutes_out
    
    
    if (hrsn < hrso)
    {
        hours_max = 24 - (hrso - hrsn);
    }
    
    else if (hrsn > hrso)
    {
        hours_max = (24 - hrso) + hrsn;
    }
    
    else
    hours_max = 0;
    
    
    hours_max = (hrso - hrsn);
    
    
    printf("Time in %d:%d\n", hrsn, minn);
    printf("Time out %d:%d\n", hrso, mino);
    printf("Parking Time:  %d:%d \n", hours_max, minutes_max);
    
    }
    
    return 0;
    
    }

  8. #23
    Registered User
    Join Date
    Feb 2010
    Posts
    36
    When i run my program it skips the Tax function in my code and i change int main to int void an it still isnt working plz help, i put "void Tax():" in the global section an it skipped it also

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    #include <math.h>
    
    char vehicle[5];
    int car;
    int truck;
    int hrsn; //Hour the vehicle entered the parking lot
    int minn; //Minute the vehicle came in the parking lot
    int hrso; //Hour the vehicle left the parking lot
    int mino; //Minute the vehicle left the parking lot
    int hr; //final hour
    int min; //final minute
    int minutes_max;//60 minutes
    int hours_max;//24 hours
    hrsn=0;
    hrso=0;
    minn=0;
    mino=0;
    hr=0;
    min=0;
    minutes_max=0;
    hours_max=0;
    
    void main()
    
    {
    
    
    printf("Where you driving a car or truck?\n");
    scanf("%s", &vehicle );
    
    while( strcmp( vehicle, "truck" ) != 0 && strcmp( vehicle, "car" ) != 0 )
    {
        printf("Please input the words Car or Truck: ");
        scanf("%s",&vehicle);
    }
    
    
    printf("What Hour did the %s enter the lot? (0-23)\n", vehicle);
    scanf("%d",&hrsn);
    while((hrsn<0 || hrsn>23))
    {
        printf("\a\a\a Please Input Value from 0-23!\n");
        scanf("%d",& hrsn);
    }
    
    {
        printf("What Minute did the %s enter the lot? (0-59)\n", vehicle);
        scanf("%d",& minn);
    }
    while((minn<0 || minn>59))
    {
        printf("\a\a\a Please Enter Correct Minute Between 0-59!\n");
        scanf("%d",& minn);
    }
    
    {
        printf("What Hour did the %s leave the lot? (0-23)\n", vehicle);
        scanf("%d",& hrso);
    }
    while((hrso<0 || hrso>23))
    {
        printf("\a\a\a Please Enter the Correct Time Between 0-23!\n");
        scanf("%d",& hrso);
    }
    
    {
        printf("What Minute did the %s leave the lot? (0-59)\n", vehicle);
        scanf("%d",& mino);
    }
    while(mino<0 || mino>59)
    {
        printf("\a\a\a PLease Enter the Correct time between 0-59!\n");
        scanf("%d",& mino);
    }
    
    {
    if(minn < mino)
    {
      minutes_max = 60 - (mino - minn);
      //minutes_max = 60 - 5
      //minutes_max = 55 minutes
    }
    else if(minn > mino)
    {
         minutes_max = (60 - minn) + mino;
         hrso = hrso-1;
    }
    
    else
      minutes_max = 0; //minutes_in equals minutes_out
    
    
    if (hrsn < hrso)
    {
        hours_max = 24 - (hrso - hrsn);
    }
    
    else if (hrsn > hrso)
    {
        hours_max = (24 - hrso) + hrsn;
    }
    
    else
    hours_max = 0;
    
    
    hours_max = (hrso - hrsn);
    
    
    printf("Time in %d:%d\n", hrsn, minn);
    printf("Parking Time:  %d:%d \n", hours_max, minutes_max);
    
    }
    
    
    }
    
    int Tax()
    {
    
    float gct;
    float price_car;
    float price_truck;
    float price;
    float finalprice;
    price=0;
    finalprice=0;
    gct=0.175; //17.5%
    price_car=0;
    price_truck=0;
    
    
    
    while(vehicle == "car")
    {
    
    if( minutes_max > 1 || minutes_max < 30)
    {
        price = price_car + 50;
    }
    else if(minutes_max > 30 || minutes_max < 60)
    {
        price = price_car + 100;
    }
    else if( hours_max >= 1)
    {
        price = (price_car+100) * hours_max;
    }
    
    finalprice = (gct * price) + price;
    
    }
    
    while(vehicle == "truck")
    {
    
    if( minutes_max > 1 || minutes_max < 30)
    {
        price = price_truck + 50;
    }
    else if(minutes_max > 30 || minutes_max < 60)
    {
        price = price_truck + 100;
    }
    else if( hours_max >= 1)
    {
        price = (price_truck+100) * hours_max;
    }
    
    finalprice = (gct * price) + price;
    
    }
    
    printf("The Final Price is: %f", finalprice);
    
    }

  9. #24
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You can't use this kind of code in C - it's not legal.
    Code:
    while(vehicle == "car")
    use this instead:

    include string.h at the top of your program, if it's not there yet.

    Code:
    if((strcmp(vehicle, "car")) == 0) {
      //they match
    }
    else {
      //they do not match
    }
    Did you get the time problem fixed yet?

  10. #25
    Registered User
    Join Date
    Feb 2010
    Posts
    36
    yes i did but now the program is skipping the tax function and i tried to use pointer but im getting a hell of a lotta errors and not understanding them

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    #include <math.h>
    
    char vehicle[5];
    int car;
    int truck;
    int hrsn; //Hour the vehicle entered the parking lot
    int minn; //Minute the vehicle came in the parking lot
    int hrso; //Hour the vehicle left the parking lot
    int mino; //Minute the vehicle left the parking lot
    int hr; //final hour
    int min; //final minute
    int minutes_max;//60 minutes
    int hours_max;//24 hours
    hrsn=0;
    hrso=0;
    minn=0;
    mino=0;
    hr=0;
    min=0;
    minutes_max=0;
    hours_max=0;
    
    void Tax(float *gct, float *price_car, float *price_truck, float *price, float *finalprice);
    
    int main(void)
    
    {
    
    float gct;
    float price_car;
    float price_truck;
    float price;
    float finalprice;
    price=0;
    finalprice=0;
    gct=0.175; //17.5%
    price_car=0;
    price_truck=0;
    
    printf("Where you driving a car or truck?\n");
    scanf("%s", &vehicle );
    
    while( strcmp( vehicle, "truck" ) != 0 && strcmp( vehicle, "car" ) != 0 )
    {
        printf("Please input the words Car or Truck: ");
        scanf("%s",&vehicle);
    }
    
    
    printf("What Hour did the %s enter the lot? (0-23)\n", vehicle);
    scanf("%d",&hrsn);
    while((hrsn<0 || hrsn>23))
    {
        printf("\a\a\a Please Input Value from 0-23!\n");
        scanf("%d",& hrsn);
    }
    
    {
        printf("What Minute did the %s enter the lot? (0-59)\n", vehicle);
        scanf("%d",& minn);
    }
    while((minn<0 || minn>59))
    {
        printf("\a\a\a Please Enter Correct Minute Between 0-59!\n");
        scanf("%d",& minn);
    }
    
    {
        printf("What Hour did the %s leave the lot? (0-23)\n", vehicle);
        scanf("%d",& hrso);
    }
    while((hrso<0 || hrso>23))
    {
        printf("\a\a\a Please Enter the Correct Time Between 0-23!\n");
        scanf("%d",& hrso);
    }
    
    {
        printf("What Minute did the %s leave the lot? (0-59)\n", vehicle);
        scanf("%d",& mino);
    }
    while(mino<0 || mino>59)
    {
        printf("\a\a\a PLease Enter the Correct time between 0-59!\n");
        scanf("%d",& mino);
    }
    
    {
    if(minn < mino)
    {
      minutes_max = 60 - (mino - minn);
      //minutes_max = 60 - 5
      //minutes_max = 55 minutes
    }
    else if(minn > mino)
    {
         minutes_max = (60 - minn) + mino;
         hrso = hrso-1;
    }
    
    else
    
      minutes_max = 0; //minutes_in equals minutes_out
    
    
    if (hrsn < hrso)
    {
        hours_max = 24 - (hrso - hrsn);
    }
    
    else if (hrsn > hrso)
    {
        hours_max = (24 - hrso) + hrsn;
    }
    
    else
    hours_max = 0;
    
    
    hours_max = (hrso - hrsn);
    
    
    printf("Time in %d:%d\n", hrsn, minn);
    printf("Parking Time:  %d:%d \n", hours_max, minutes_max);
    
    }
    
    
    
    Tax(&gct,&price_car,&price_truck,&price,&finalprice);
    
    
    }
    
    
    void Tax(float *gct, float *price_car, float *price_truck, float *price, float *finalprice)
    {
    
    if((strcmp(vehicle, "car")) == 0)
    {
    
    if( minutes_max > 1 || minutes_max < 30)
    {
        price = price_car + 50;
    }
    else if(minutes_max > 30 || minutes_max < 60)
    {
        price = price_car + 100;
    }
    else if( hours_max >= 1)
    {
        price = (price_car+100) * hours_max;
    }
    
    finalprice = (gct * price) + price;
    
    }
    
    if((strcmp(vehicle, "truck")) == 0)
    {
    
    if( minutes_max > 1 || minutes_max < 30)
    {
        price = price_truck + 50;
    }
    else if(minutes_max > 30 || minutes_max < 60)
    {
        price = price_truck + 100;
    }
    else if( hours_max >= 1)
    {
        price = (price_truck+100) * hours_max;
    }
    
    finalprice = (gct * price) + price;
    
    }
    
    printf("The Final Price is: %f", finalprice);
    return 0;
    }

  11. #26
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    The Tax function wasn't getting called because you ended main with a curly brace, before the line of code that was calling Tax().

    Remove the curly brace in red, from your code in main():
    Code:
    printf("Parking Time:  %d:%d \n", hours_max, minutes_max);
    
    }
    
    
    
    Tax(&gct,&price_car,&price_truck,&price,&finalprice);
    
    
    }

  12. #27
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Adak View Post
    The Tax function wasn't getting called because you ended main with a curly brace, before the line of code that was calling Tax().
    For that matter... he could probably take out half the brace pairs and still have a working program.

  13. #28
    Registered User
    Join Date
    Feb 2010
    Posts
    36
    Tried it and it still doesnt work

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    #include <math.h>
    
    char vehicle[5];
    int car;
    int truck;
    int hrsn; //Hour the vehicle entered the parking lot
    int minn; //Minute the vehicle came in the parking lot
    int hrso; //Hour the vehicle left the parking lot
    int mino; //Minute the vehicle left the parking lot
    int hr; //final hour
    int min; //final minute
    int minutes_max;//60 minutes
    int hours_max;//24 hours
    hrsn=0;
    hrso=0;
    minn=0;
    mino=0;
    hr=0;
    min=0;
    minutes_max=0;
    hours_max=0;
    
    void Tax(float *gct, float *price_car, float *price_truck, float *price, float *finalprice);
    
    int main(void)
    
    {
    
    float gct;
    float price_car;
    float price_truck;
    float price;
    float finalprice;
    price=0;
    finalprice=0;
    gct=0.175; //17.5%
    price_car=0;
    price_truck=0;
    
    printf("Where you driving a car or truck?\n");
    scanf("%s", &vehicle );
    
    while( strcmp( vehicle, "truck" ) != 0 && strcmp( vehicle, "car" ) != 0 )
    {
        printf("Please input the words Car or Truck: ");
        scanf("%s",&vehicle);
    }
    
    
    printf("What Hour did the %s enter the lot? (0-23)\n", vehicle);
    scanf("%d",&hrsn);
    while((hrsn<0 || hrsn>23))
    {
        printf("\a\a\a Please Input Value from 0-23!\n");
        scanf("%d",& hrsn);
    }
    
    {
        printf("What Minute did the %s enter the lot? (0-59)\n", vehicle);
        scanf("%d",& minn);
    }
    while((minn<0 || minn>59))
    {
        printf("\a\a\a Please Enter Correct Minute Between 0-59!\n");
        scanf("%d",& minn);
    }
    
    {
        printf("What Hour did the %s leave the lot? (0-23)\n", vehicle);
        scanf("%d",& hrso);
    }
    while((hrso<0 || hrso>23))
    {
        printf("\a\a\a Please Enter the Correct Time Between 0-23!\n");
        scanf("%d",& hrso);
    }
    
    {
        printf("What Minute did the %s leave the lot? (0-59)\n", vehicle);
        scanf("%d",& mino);
    }
    while(mino<0 || mino>59)
    {
        printf("\a\a\a PLease Enter the Correct time between 0-59!\n");
        scanf("%d",& mino);
    }
    
    
    if(minn < mino)
    {
      minutes_max = 60 - (mino - minn);
      //minutes_max = 60 - 5
      //minutes_max = 55 minutes
    }
    else if(minn > mino)
    {
         minutes_max = (60 - minn) + mino;
         hrso = hrso-1;
    }
    
    else
    
      minutes_max = 0; //minutes_in equals minutes_out
    
    
    if (hrsn < hrso)
    {
        hours_max = 24 - (hrso - hrsn);
    }
    
    else if (hrsn > hrso)
    {
        hours_max = (24 - hrso) + hrsn;
    }
    
    else
    hours_max = 0;
    
    
    hours_max = (hrso - hrsn);
    
    
    printf("Time in %d:%d\n", hrsn, minn);
    printf("Parking Time:  %d:%d \n", hours_max, minutes_max);
    
    Tax(&gct,&price_car,&price_truck,&price,&finalprice);
    
    
    
    
    
    
    }
    
    
    void Tax(float *gct, float *price_car, float *price_truck, float *price, float *finalprice)
    {
    
    if((strcmp(vehicle, "car")) == 0)
    {
    
    if( minutes_max > 1 || minutes_max < 30)
    {
        price = price_car + 50;
    }
    else if(minutes_max > 30 || minutes_max < 60)
    {
        price = price_car + 100;
    }
    else if( hours_max >= 1)
    {
        price = (price_car+100) * hours_max;
    }
    
    finalprice = (gct * price) + price;
    
    }
    
    if((strcmp(vehicle, "truck")) == 0)
    {
    
    if( minutes_max > 1 || minutes_max < 30)
    {
        price = price_truck + 50;
    }
    else if(minutes_max > 30 || minutes_max < 60)
    {
        price = price_truck + 100;
    }
    else if( hours_max >= 1)
    {
        price = (price_truck+100) * hours_max;
    }
    
    finalprice = (gct * price) + price;
    
    }
    
    printf("The Final Price is: %f", finalprice);
    return 0;
    }

  14. #29
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Your calculations in TAX() are based on the variable minutes_max, but you didn't bring minutes_max, into that function.

  15. #30
    Registered User
    Join Date
    Feb 2010
    Posts
    36
    Thx didnt even realise that i carried over minutes_max , hours_max and vehicle and it runs now but it crashes when i input the last variable for the main() part of the program

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    #include <math.h>
    
    char vehicle[5];
    int car;
    int truck;
    int hrsn; //Hour the vehicle entered the parking lot
    int minn; //Minute the vehicle came in the parking lot
    int hrso; //Hour the vehicle left the parking lot
    int mino; //Minute the vehicle left the parking lot
    int hr; //final hour
    int min; //final minute
    int minutes_max;//60 minutes
    int hours_max;//24 hours
    hrsn=0;
    hrso=0;
    minn=0;
    mino=0;
    hr=0;
    min=0;
    minutes_max=0;
    hours_max=0;
    
    void Tax(float *gct, float *price_car, float *price_truck, float *price, float *finalprice, int *minutes_max, int *hours_max, char *vehicle[5]);
    
    int main(void)
    
    {
    
    float gct;
    float price_car;
    float price_truck;
    float price;
    float finalprice;
    price=0;
    finalprice=0;
    gct=0.175; //17.5%
    price_car=0;
    price_truck=0;
    
    printf("Where you driving a car or truck?\n");
    scanf("%s", &vehicle );
    
    while( strcmp( vehicle, "truck" ) != 0 && strcmp( vehicle, "car" ) != 0 )
    {
        printf("Please input the words Car or Truck: ");
        scanf("%s",&vehicle);
    }
    
    
    printf("What Hour did the %s enter the lot? (0-23)\n", vehicle);
    scanf("%d",&hrsn);
    while((hrsn<0 || hrsn>23))
    {
        printf("\a\a\a Please Input Value from 0-23!\n");
        scanf("%d",& hrsn);
    }
    
    {
        printf("What Minute did the %s enter the lot? (0-59)\n", vehicle);
        scanf("%d",& minn);
    }
    while((minn<0 || minn>59))
    {
        printf("\a\a\a Please Enter Correct Minute Between 0-59!\n");
        scanf("%d",& minn);
    }
    
    {
        printf("What Hour did the %s leave the lot? (0-23)\n", vehicle);
        scanf("%d",& hrso);
    }
    while((hrso<0 || hrso>23))
    {
        printf("\a\a\a Please Enter the Correct Time Between 0-23!\n");
        scanf("%d",& hrso);
    }
    
    {
        printf("What Minute did the %s leave the lot? (0-59)\n", vehicle);
        scanf("%d",& mino);
    }
    while(mino<0 || mino>59)
    {
        printf("\a\a\a PLease Enter the Correct time between 0-59!\n");
        scanf("%d",& mino);
    }
    
    
    if(minn < mino)
    {
      minutes_max = 60 - (mino - minn);
      //minutes_max = 60 - 5
      //minutes_max = 55 minutes
    }
    else if(minn > mino)
    {
         minutes_max = (60 - minn) + mino;
         hrso = hrso-1;
    }
    
    else
    
      minutes_max = 0; //minutes_in equals minutes_out
    
    
    if (hrsn < hrso)
    {
        hours_max = 24 - (hrso - hrsn);
    }
    
    else if (hrsn > hrso)
    {
        hours_max = (24 - hrso) + hrsn;
    }
    
    else
    hours_max = 0;
    
    
    hours_max = (hrso - hrsn);
    
    
    printf("Time in %d:%d\n", hrsn, minn);
    printf("Parking Time:  %d:%d \n", hours_max, minutes_max);
    
    Tax(&gct,&price_car,&price_truck,&price,&finalprice,&minutes_max,&hours_max,&vehicle[5]);
    
    
    }
    
    
    void Tax(float *gct, float *price_car, float *price_truck, float *price, float *finalprice, int *minutes_max, int *hours_max, char *vehicle[5])
    {
    
    if((strcmp(*vehicle, "car")) == 0)
    {
    
    if( *minutes_max > 1 || *minutes_max < 30)
    {
        *price = *price_car + 50;
    }
    else if(*minutes_max > 30 || *minutes_max < 60)
    {
        *price = *price_car + 100;
    }
    else if( *hours_max >= 1)
    {
        *price = (*price_car+100) * *hours_max;
    }
    
    *finalprice = (*gct * *price) + *price;
    
    }
    
    if((strcmp(*vehicle, "truck")) == 0)
    {
    
    if( *minutes_max > 1 || *minutes_max < 30)
    {
        *price = *price_truck + 50;
    }
    else if(*minutes_max > 30 || *minutes_max < 60)
    {
        *price = *price_truck + 100;
    }
    else if( *hours_max >= 1)
    {
        *price = (*price_truck+100) * *hours_max;
    }
    
    *finalprice = (*gct * *price) + *price;
    
    }
    
    printf("The Final Price is: %f", *finalprice);
    
    }

Page 2 of 5 FirstFirst 12345 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. im a noob at c++, do you think so?
    By belRasho in forum C++ Programming
    Replies: 6
    Last Post: 04-25-2010, 11:02 PM
  2. c program that accepts and executes commands?
    By Cimposter in forum C Programming
    Replies: 3
    Last Post: 09-30-2009, 02:58 PM
  3. Replies: 2
    Last Post: 09-16-2009, 06:00 AM
  4. Console Program Problem
    By Breach23 in forum C++ Programming
    Replies: 3
    Last Post: 10-19-2001, 12:35 AM

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