I need a lot of help with this program:
I know this is a homework problem but I am really struggling with it.

This program requires you to input information about rickshaw taxi fares. The ODUSPORTS is a student powered on-campus rickshaw transportation system. Upon departure, a ticket is created indicating the hour and minute the trip begins. When the student has pulled the rickshaw and its occupants to the desired location, the ticket is punched again, indicating the hour and minute the trip ends. There are three types of customers that can be accommodated by the system: single passengers, couples, and groups of three people. All passengers traveling together must proceed to the same destination location. Your job is to write a program that calculates the amount owed by the customer for the trip. The input for a trip will consist of a character and four integer values. The character will indicate the type of fare, and the integer values will reflect the departure time of the rickshaw from the point of origin, and the arrival time at the destination ( both in hours and minutes) of the rickshaw fares.
• The character will be either S, C, or G; this indicates single, couple, or group.
• The first integer ( 0 <= hr_in < 24) represents the hour of the departure time of the rickshaw
• The second integer ( 0 <= min_in < 60) represents the minutes of the departure time of the rickshaw
• The third integer ( 0 <= hr_out < 24) represents the hour of the arrival time of the rickshaw
• The fourth integer ( 0 <= min_out < 60) represents the minutes of the arrival time of the rickshaw

//------------------------------------… Code

#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <time.h>
#include <assert.h>

 
using namespace std;
 
int main()
{
     
    // write an alogorithm to establish the steps to take to solve the problem
    //(1) Declare some variables to work with
  char fare;
  char choice = 'Y';
  int hrIn, minIn, hrOut, minOut;                              
  float hours; 
  float minutes;
  float total_minutes;                     
  double cost;
  float charge;
  string am,pm;
  

 while (choice == 'Y')
  
  {
    //(2) OUtput reqd info and user message

  cout << "This program will calculate a single, couple, or group "
       << "\nfare amount which is then owed by the customer for the trip.\n"
       << "\nTo calculate a single fare amount, input S (or s)"
       << "\nTo calculate a couple fare amount, input C (or c)"
       << "\nTo calculate a group fare amount, input G (or g)"
       << " \n\nInput S, C, or G: ";
  cin >> fare;
  
  // end of description
  
  //-------------------------------------------------------
  if(fare=='S'||fare=='s')
  {
   cout << "\nWhat hour did they depart? ";
   cin >> hrOut;
   cout << "\nWhat minute did they depart? ";
   cin >> minOut;
   cout << "\nYou entered for departure: " << hrOut << ":" << minOut << endl;
   cout << "\nWhat hour did they arrive? ";
   cin >> hrIn;
   cout << "\nWhat minute did they arrive? ";
   cin >> minIn; 
   cout << "\nYou entered for arrival: " << hrIn << ":" << minIn << "\n" << endl;
   cout << "A rickshaw departed at " << hrOut << ":" << minOut
        << " and arrived at " << hrIn << ":" << minIn << " with a single customer.\n" << endl;
        
 
  if(hrIn <= hrOut && minIn <= minOut && total_minutes <=30)
  {
          hours = (hrIn - hrOut) + 11.0;
          cout << "You arrived in " << hours << " hour(s)";
          minutes = minIn - minOut + 60.0;
          cout << " and " << minutes << " minute(s) ";
          total_minutes = (hours * 60) + minutes;
          cout << ", or in a total of " << total_minutes << " minutes.\n" << endl;

          cout << fixed << showpoint << setprecision(2);

          charge = 7.00;

          cout << "You owe $" << charge << " dollars.\n" << endl; 
          }
          else 
          {
          hours = (hrIn - hrOut);
          cout << "You arrived in " << hours << " hour(s)";
          minutes = minIn - minOut;
          cout << " and " << minutes << " minute(s) ";
          total_minutes = (hours * 60) + minutes;
          cout << ", or in a total of " << total_minutes << " minutes.\n" << endl;
          
          cout << fixed << showpoint << setprecision(2);

          charge = 7.00 + (((total_minutes) - 30) * 1.50);

          cout << "You owe $" << charge << " dollars.\n" << endl; 
}
}
// end of S if

//-----------------------------------------------------------------------
        
        cout << "Would you like to perform another calculation (Y/N)? ";
        cin >> choice;
        
        cout << "\n";

        }
                                                              
                                                                                                                                                  
     system("\npause");
     return 0; 
}

Additional Details
For example G 11 30 12 10

A rickshaw left at 11:30 and arrived at 12:10 with a group of customers.

Student-Powered Rickshaw fees are detailed in the table that follows:

Type of fare Initial rate Rate for additional time
Single First 30 minutes are $7.00
$1.50 per minute after the first 30
Couple First 20 minutes are $10.50
$2.50 per minute after the first 20
Group First 15 minutes are $16.00
$4.00 per minute after the first 15

Notes:
1. Groups whose additional time exceeds 30 minutes, must pay an additional $50.00 fee.
2. Your program should prompt for each piece of input data separately.
3. The output should include a labeled echo print of the input values, the actual time that the trip took ( hours and minutes), the number of minutes the customer will be charged for, and the total charges.
4. Print an error message for illegal fare types.
5. No fare is allowed to last for more than 24 hours. You do not need to check for this. Also, you may assume that the departure time is less than arrival time.

Recommended Answers

All 3 Replies

First: use [code] tags.
Second: What exactly is the problem? Are you getting an error from the compiler? If so, what is it? Is it a run-time error?

My problem is that when I enter an hrOut > hrIn, I get a postive number but when I enter an hrIn < hrOut, I get a negative number. I want to get them to be both positive. Same for minIn and minOut.

Hmmm... I think you may have got some things a little confused.

  • You should probably print an error and ask again for the times if hrOut > hrIn because that would mean that they arrived back before they set out!
  • This condition: if(hrIn <= hrOut && minIn <= minOut && total_minutes <=30) uses total_minutes before it has been initialised, so you can't know what value total_minutes has.
  • Think again about how you calculate the total time... maybe write out on paper, step-by-step, what results are produced by these lines:
    hours = (hrIn - hrOut) + 11.0;
    cout << "You arrived in " << hours << " hour(s)";
    minutes = minIn - minOut + 60.0;
    cout << " and " << minutes << " minute(s) ";
  • Check again the example input for the program: G 11 30 12 10 . Is this how your program is taking the input?
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.