Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8806115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:03:07+00:00 2026-06-14T02:03:07+00:00

So its a Friday, Ive been working this app and my head is about

  • 0

So its a Friday, Ive been working this app and my head is about to explode. I can’t find the problem anywhere!!! I am a beginner coder so I am hoping the gods of stackoverflow can guide me in the right direction or provide some feedback!! :]

This console app is just a simple parking time ticket. The code complies fine with no errors. But my math is all messed up!

Here is a sample result: With time entered as 3:50 and exit 5:29 with vehicle as T.

 TIME-IN          -858993460:858993460
 TIME-OUT                -858933460:-858993460

 PARKING TIME             0:-858993460

 TOTAL CHARGE             -214748352.00

And here is my code

 #include <iostream>   //used for cout/cin
 #include <iomanip>   //used to manipulate data 


 void getData(int* ehour, int* emin, int* exhour, int* exmin);
 void rate(int exhour, int exmin, int ehour, int emin, int* thour, int* tmin, int* round);
 void charge(char* vehic, float* rate1, float* rate2, int ehour);
 void result(int exhour, int exmin, int ehour, int emin, int thour, float rate1, float rate2, int round, float total);

 int main(void)
 {
   char vehic;
   int ehour;
   int emin;
   int exhour;
   int exmin;
   int thour;
   int tmin;
   int round;

   float rate1;
   float rate2;
   float total;

   getData(&ehour, &emin, &exhour, &exmin);
   rate(exhour, exmin, ehour, emin, &thour, &tmin, &round);
   charge(&vehic, &rate1, &rate2, ehour);
   total= rate1 + rate2;
   result( exhour, exmin, ehour, emin, thour, rate1, rate2, round, total);
   return 0;
 }

  void getData(int* ehour, int* emin, int* exhour, int* exmin)
 {
   char v;
   printf("Enter C for car, B for bus, T for truck: ");
   scanf("%c", &v);
   printf("\nHour vehicle entered 0-24: ");
   scanf("%d", &ehour);
   printf("\nMinute vehicle entered 0-60: ");
   scanf("%d", &emin);
   printf("\nHour vehicle exited 0-24: ");
   scanf("%d", &exhour);
   printf("\nMinute vehicle exited 0-60: ");
   scanf("%d", &exmin);
   return;
 }
 void rate(int exhour, int exmin, int ehour, int emin, int* thour, int* tmin, int* round)
 {
   if(emin < exmin)
   {
          emin= emin + 60;
          exhour= exhour - 1;
   }
   *thour = ehour - exhour;
   *tmin = emin - exmin;
   if ((*tmin > 0 && *tmin <= 60))
   {
          *thour = *thour + 1;
          *round = *tmin * 0;
   }
   return;
 }
 void charge(char* vehic, float* rate1, float* rate2, int ehour)
 {
   switch (*vehic)
   {
   case 'c': if (ehour <= 3)
                   {
                         *rate1 = 0.00;
                         if (ehour > 3)
                              *rate2 = 1.25 * (ehour - 3);
                   }
                   break;

   case 'b': if (ehour <= 2)
                   {
                         *rate1 = 2.00 * ehour;
                         if (ehour > 2)
                                *rate2 = 2.50 * (ehour - 2);
                   }
                   break;
   case 't': if (ehour <= 1)
                   {
                         *rate1 = 3.75 * ehour;
                         if (ehour > 1)
                         *rate2 = 4.50 * (ehour - 1);
                   }
                   break;
   }
   return;
 }
 void result(int exhour, int exmin, int ehour, int emin, int thour, float rate1, float rate2, int round, float total)
 {
   printf("\n\t\t PARKING LOT CHARGE \t\t\n");
   printf("\nType of vehicle: Car or Bus or Truck");
   printf("\nTIME-IN\t\t %d:%d", ehour, emin);
   printf("\nTIME-OUT\t\t %d:%d", exhour, exmin);
   printf("\n\t\t\t --------");
   printf("\nPARKING TIME\t\t %d:%d", thour, round);
   printf("\n\t\t\t --------");
   total= rate1 + rate2;
   printf("\nTOTAL CHARGE\t\t %4.2f\n\n", total);

   return;
   }

I am sorry this is alot of code! I am just so puzzled!!! Are my ints not formatted correctly? Is the math wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T02:03:09+00:00Added an answer on June 14, 2026 at 2:03 am
    char v;
    printf("Enter C for car, B for bus, T for truck: ");
    scanf("%c", &v);
    printf("\nHour vehicle entered 0-24: ");
    scanf("%d", ehour);
    printf("\nMinute vehicle entered 0-60: ");
    scanf("%d", emin);
    printf("\nHour vehicle exited 0-24: ");
    scanf("%d", exhour);
    printf("\nMinute vehicle exited 0-60: ");
    scanf("%d", exmin);
    

    You took the address of the parameters, which were already pointers.


    As a general finger exercise, here’s what you could do in more typical C++ style:

    /////////////////////////////////////
    // timepoint classes (booking.hpp)
    
    struct timepoint
    {
        int hour, minute;
    
        timepoint normalized()                     const; 
        int totalMinutes    ()                     const; 
        int roundedHours    ()                     const; 
        timepoint operator- (timepoint const& rhs) const; 
    };
    
    struct booking_t
    {
        char vehicle;
        timepoint enter, exit;
    
        timepoint parked() const { return exit - enter; }
    };
    
    /////////////////////////////////////
    // main program (main.cpp)
    booking_t inputData();
    void displayBill(booking_t const& booking);
    
    int main(void)
    {
        auto booking = inputData();
        displayBill(booking);
    }
    
    /////////////////////////////////////
    // timepoint methods (booking.cpp)
    
    timepoint timepoint::normalized() const
    {
        timepoint tmp { (hour + minute/60) % 24, minute % 60 };
        while (tmp.minute < 0) tmp.hour--, tmp.minute+=60;
        while (tmp.hour   < 0) tmp.hour+=24;
        return tmp;
    }
    
    int timepoint::roundedHours() const
    {
        return (totalMinutes()-1) / 60 + 1; // TODO check rounding logic
    }
    
    int timepoint::totalMinutes() const
    {
        return hour*60 + minute;
    }
    
    timepoint timepoint::operator-(timepoint const& rhs) const
    {
        return timepoint { 0, totalMinutes() - rhs.totalMinutes() } .normalized();
    }
    
    #include <iostream>   //used for cout/cin
    
    timepoint getTime(std::string label)
    {
        int hour, minute;
        std::cout  << "\nHour "   << label << " 0-24: ";
        std::cin >> hour;
        std::cout  << "\nMinute " << label << " 0-60: ";
        std::cin >> minute;
        return { hour, minute };
    }
    
    /////////////////////////////////////
    // global functions - input
    booking_t inputData()
    {
        std::cout << "Enter C for car, B for bus, T for truck: ";
        char v;
        std::cin >> v;
        auto entered = getTime("vehicle entered");
        auto exited  = getTime("vehicle exited");
        return { v, entered.normalized(), exited.normalized() };
    }
    
    /////////////////////////////////////
    // calculation + billing
    #include <sstream>
    #include <iomanip>   //used to manipulate data 
    #include <map>
    
    static std::ostream& operator <<(std::ostream& os, timepoint const& tp)
    {
        std::ostringstream oss;
        oss << std::setw(2) << std::setfill('0') << tp.hour << ':' 
            << std::setw(2) << std::setfill('0') << tp.minute;
        return os << oss.str();
    }
    
    std::pair<float,float> charge(booking_t const& booking)
    {
        struct tariff_t { int threshold; float rate1, rate2; };
        const static auto tariffs = std::map<char, tariff_t> {
            { 'c', { 3, 0   , 1.25 } },
            { 'b', { 2, 2.  , 2.5  } },
            { 't', { 1, 3.75, 4.5 } } ,
        };
    
        auto& tariff = tariffs.at(std::tolower(booking.vehicle));
        auto  parked = booking.parked().roundedHours();
    
        return std::make_pair(
                tariff.rate1 * std::min(tariff.threshold, parked)    ,
                tariff.rate2 * std::max(0, parked - tariff.threshold));
    }
    
    void displayBill(booking_t const& booking)
    {
        std::cout << "\n\n    PARKING LOT CHARGE\n";
        std::cout << "Type of vehicle: Car or Bus or Truck\n";
        std::cout << "TIME-IN         " << booking.enter << "\n";
        std::cout << "TIME-OUT        " << booking.exit  << "\n";
        std::cout << "                " << "--------\n";
        std::cout << "PARKING TIME    " << booking.parked() << "\n";
        std::cout << "        ROUNDED " << booking.parked().roundedHours() << "\n";
        std::cout << "                " << "--------\n";
    
        auto  rates = charge(booking);
        float total = rates.first + rates.second;
        std::cout << "TOTAL CHARGE    " << std::fixed << std::setw(7) << std::setprecision(2) << total << "\n\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm probably being stupid, because its Friday afternoon, but I just can't work this
Hi I have been searching online for information about this but can't seem to
It's late on a Friday and I'm scratching my head on this one. I'm
I've been scratching my head over this one for a couple hours now, I've
OK, its Friday afternoon and I need to get this done: The following xml
Its friday, and in local time the clock is 3.22pm, so my brain wont
I've got this XML; <ChartXml> <Category type=xAxis> <Value>Mon</Value> <Value>Tue</Value> <Value>Wed</Value> <Value>Thurs</Value> <Value>Friday</Value> </Category> </ChartXml>
In python how do I check if its a weekday (Monday - Friday) and
Happy Friday! I assume somebody out there has a simple answer to this question
Its about a small android application that will take hours as input from user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.