Friday, 27 September 2013

C# Parking Fee Program [on hold]

C# Parking Fee Program [on hold]

I have to write a program for my Comp Prog I class. Below is the
assignment and the code I have written so far. Any help would be
appreciated. It runs but I am having trouble determining the best way to
do the calculations. I am attempting to get the long term portion
completed and then I was going to attempt to apply that to the short term
solution as well.
The Greater Providence Airport asks you to design a C# console application
program to calculate parking charge for their customers. The program can
be used to calculate either long-term parking or short-term parking. The
charge is calculated according the following rules:
Long-term Parking:
Input : Total number of hours (an integer)
The minimum charge is one full day (24 hours) $4.50 Any additional full
day (24 hours) is $4.00 each day If the last day's parking is less than 24
hours, the charge is prorated according to the number of hours parked,
i.e., if only 4 hours are parked, the charge is $4.00 * (4/ 24)
If you are a Greater Providence Airport employee, you get 75% discount.
Short-term Parking:
Input : Total number of minutes (an integer)
For each 24-hour period: The first ½ hour: $1.50 The next three ½ hour:
$1.25 each ½ hour Each ½ hour afterward $0.75 each
A fraction of ½ hour is counted as a whole ½ hour.
For each 24-hour period, the maximum charge is $12.00. That is if the
total amount exceeds $12.00, only $12.00 will be charged.
If you are a Greater Providence Airport employee, you pay only $1.25 for
each time you park at Short-term parking as long as the duration is no
more than 24 hours. Otherwise the charge will repeat for each 24-hour
period.
Output: Receipt should be nicely designed. For example:
Greater Providence Airport Parking Charge Short-term Parking: 148 minutes
Total Charge: $6.00 or Greater Providence Airport Parking Charge Long-term
Parking: 68 hours Total Charge: $11.83 Employee Discount: $ 8.87 Actual
Charge: $ 2.96
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace parking
{
class Program
{
static void Main(string[] args)
{
double minCharge = 4.50;
int hours = 0;
int id = 0;
double discount = 4.50*.75;
double calculateCharge;
Console.WriteLine("Enter hours parked:");
hours = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Are you an Employee? Enter 1 for yes and 0
for no:");
id = Convert.ToInt32(Console.ReadLine());
if (hours <= 24)
{
calculateCharge = minCharge;
Console.WriteLine("The cost is {0}",
Convert.ToDecimal(calculateCharge));
}
if (hours <= 24 && id >= 1)
{
calculateCharge = (minCharge-discount);
Console.WriteLine("The cost is {0}",
Convert.ToDecimal(calculateCharge));
}
if(hours >24) {
calculateCharge = (((hours%24)/24)*4);
Console.WriteLine("The cost is {0}", calculateCharge);
}
if (hours > 24 && id >=1)
{
calculateCharge = (((minCharge+hours % 24) / 24) * 4)-0.75;
Console.WriteLine("The cost is {0}", calculateCharge);
}
Console.ReadKey(true);
}
}
}

No comments:

Post a Comment