Solution Problems code error

Thank you for looking.

So this program is supposed to take the users input
which is vehicle type and minutes parked
and display hours parked vehicle type and the fee for parking.

So the first problem I have is that how can I give a discount
of -2 or -1 hours with out going negative?

The next problem is how can I display the vehicle type from the
input?

and finally why is my program jumping to the end after the user
inputs vehicle type?
So this program is supposed to take the users input
which is vehicle type and minutes parked
and display hours parked vehicle type and the fee for parking.

So the first problem I have is that how can I give a discount
of -2 or -1 hours with out going negative?

The next problem is how can I display the vehicle type from the
input?

and finally why is my program jumping to the end after the user
inputs vehicle type?


<code> Program Name :
* Author :
* Date :
* Course/Section : CSC110-1001
* Program Description: This program will determine the total cost
* of parking for cars and trucks. It will do this by taking the
* amount of time each vehicle has been parked and multiply that
* by the the cost of parking and subtracting the discount of each
* vehicle
*
*
* BEGIN Lab 04 - Calculate the total for park
* Input vehicle type
* Input min parked
* Clear screen
* IF (invalid vehicle type)
* Display error;
* ELSE
* IF (vehicle is a car)
* vehicle make = car
* Divided Minutes by 60
Round number to next whole number
subtract 2 from whole number
Multiply rate by hours
* ELSE
* vehicle make = truck
* Divided Minutes by 60
Round number to next whole number
subtract 1 from whole number
Multiply rate by hours
* END IF
* Calculate hours parked
* Calculate fee
* Display Receipt
* END IF
* END Lab 04 - Calculate the total for park
**********************************************************************/
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

void main()
{
// local constants
const char CAR = 'C';
const char TRUCK = 'T';
const float RATE_C = 1.75;
const float RATE_T = 3.00;
const int DISCOUNT_C = 120;
const int DISCOUNT_T = 60;

// local variables
int Type; //First Number
float Min ;
float Park_Fee;
int Hours;

/*********************************************************************/

//Prompt for number input
cout << "\n\n\n\n\n\n\n";
cout << setw(52) << "--------------------------------" << endl;
cout << setw(50) << " Vehicle Type & Minutes parked " << endl;
cout << setw(52) << "--------------------------------" << endl;
cout << "\n" << setw (46) << " Vehicle Type: ";
cin >> Type;
cout << "\n" << setw (46) << " Minutes Parked: ";
cin >> Min;

// Clear the screen
system ("cls");

//Calculate the product of the two numbers

if (Type != 'C' && Type != 'T')
{
cout<< setw(46) << "Type Invalid" << endl;
}

else
{

if(Type = 'C')
{

Hours = ceil (Min / 60);
Hours = Hours - 2;
Park_Fee = RATE_C * Hours;
}
else (Type = 'T');
{

Hours = ceil (Min/60);
Park_Fee = RATE_T * Hours;
}

//Output product of the largest two numbers
cout << setiosflags (ios::fixed) << setprecision(2);
cout << "\n\n\n\n\n\n\n";
cout << setw(47) << "---------------" << endl;
cout << setw(45) << " Vehicle Type " << setw(2) << Type << endl;
cout << setw(45) << " Hours Parked " << setw(2) << Hours <<endl;
cout << setw(45) << " Parking Fee " << setw(2) << Park_Fee << endl;
cout << setw(47) << "---------------" << endl;
cout << "\n\n\n\n";
}
} // end main program
</code>
So the first problem I have is that how can I give a discount
of -2 or -1 hours with out going negative?


You can't just go:

number -= otherNumber;
?

The next problem is how can I display the vehicle type from the
input?


When you get the vehicle type from the user just analyze the data (through an if-else or switch statement) and print out the appropriate message.

and finally why is my program jumping to the end after the user
inputs vehicle type?


Jumping to the end as in the end of the output? Or just flashes?
Last edited on
It jumps right to output screen
Please edit your post and add [ code ] [ /code ] (minus the spaces) tags to keep indentation.
Well thank you for helping. The first problem is fixed.

the second one still not sure how to convert const char car = 'c' to display car

Also my if statement is not working right.
When it displays output The error message always displays.
Also it skips the if statment for car and just displays the results as if user put in truck?

<code>
void main()
{
// local constants
const char CAR ='C';
const char TRUCK = 'T';
const float RATE_C = 1.75;
const float RATE_T = 3.00;
const int DISCOUNT_C = 120;
const int DISCOUNT_T = 60;

// local variables
char Type; //Vehicale Type
float Min ; //Minutes Parked
float Park_Fee; //Fee to park
int Hours; //Hours Parked

/*********************************************************************/

//Prompt for number input
cout << "\n\n\n\n\n\n\n";
cout << setw(52) << "--------------------------------" << endl;
cout << setw(50) << " Vehicale Type & Minutes parked " << endl;
cout << setw(52) << "--------------------------------" << endl;
cout << "\n" << setw (46) << " Vehicale Type: ";
cin >> Type;
cout << "\n" << setw (46) << " Minutes Parked: ";
cin >> Min;

// Clear the screen
system ("cls");

//Calculate the product of the two numbers
if(Type != 'C' && Type != 'T')

cout << setw(50) << " Invaled type" << endl;

else
{

if(Type = 'C')
{

Hours = ceil (Min / 60);
Hours = Hours -= 2;
Park_Fee = RATE_C * Hours;
}

else (Type = 'T');
{

Hours = ceil (Min/60);
Hours = Hours -= 1;
Park_Fee = RATE_T * Hours;
}

//Output product of the largest two numbers
cout << setiosflags (ios::fixed) << setprecision(2);
cout << "\n\n\n\n\n\n\n";
cout << setw(47) << "---------------" << endl;
cout << setw(45) << " Vehicle Type " << setw(2) << Type << endl;
cout << setw(45) << " Hours Parked " << setw(2) << Hours <<endl;
cout << setw(45) << " Parking Fee " << setw(2) << Park_Fee << endl;
cout << setw(47) << "---------------" << endl;
cout << "\n\n\n\n";
}


} // end main program





</code>
Last edited on
Topic archived. No new replies allowed.