My code is not giving the desired output. I was wondering if you guys had any input. I am currently working on another version, however if there is a way to fix this one i'd love to know.
The phone company uses the following rate structure for calls from San Francisco to Seattle, Washington:
Any call started at or after 6:00 pm (1800) but before 8:00 am (800) is discounted 50%.
All calls are subject to a 4% federal tax.
The regular rate is $0.35 per minute.
Any call longer than 60 minutes receives a 16% discount on its cost (after any other discount is subtracted but before tax is added).
Write a program that reads from the user the start time for a call based on a 24-hour clock and the length of the call in minutes. The gross cost (before any discount or tax) should be printed, and then the net cost (after discounts and taxes). Turn in 4 outputs for this exercise, showing that your program works in each of the following 4 cases. Use the input examples shown here, don't make up your own.
Sample output 1:
Enter start time: 2322
Enter length of call in minutes: 67
gross cost: $23.45
net cost: $10.24
Sample output 2:
Enter start time: 759
Enter length of call in minutes: 10
gross cost: $3.50
net cost: $1.82
Sample output 3:
Enter start time: 1300
Enter length of call in minutes: 100
gross cost: $35.00
net cost: $30.58
Sample output 4:
Enter start time: 1300
Enter length of call in minutes: 10
gross cost: $3.50
net cost: $3.64
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
#include <iostream>
using namespace std;
int main()
{
// Assign variables and values
int start_time;
int Length_of_call;
const float federal_tax = .04;
const float regular_rate = .35;
const float with_discount = .05;
const float discount_PerMin = .16;
float gross_Cost;
float PriceofStartTime;
float PriceofLengthofCall;
float net_Cost;
cout << " Enter start time (0-2400):" <<endl;
cin>> start_time;
cout<< "Enter the length of the call (minutes):" <<endl;
cin>> Length_of_call;
//Discounted PriceofStartTime. ( by .05)
if (start_time >=1800 || start_time<800)
if (Length_of_call<60)
{ PriceofStartTime = (start_time*federal_tax);
PriceofLengthofCall = (Length_of_call*regular_rate);
gross_Cost = PriceofStartTime + PriceofLengthofCall;
cout<< " Gross cost:"<<gross_Cost<<endl;
net_Cost = (PriceofStartTime*with_discount) + PriceofLengthofCall;
cout<< " Net Cost: " <<endl;
}
// Only PriceofLengthofCall will be discounted by
else if (start_time<1800 || start_time>800)
if (Length_of_call>60)
{ PriceofStartTime = (start_time*federal_tax);
PriceofLengthofCall = (Length_of_call*regular_rate);
gross_Cost = PriceofStartTime + PriceofLengthofCall;
cout<< " Gross cost:"<<gross_Cost<<endl;
net_Cost = PriceofStartTime + (PriceofLengthofCall*discount_PerMin);
cout << " Net Cost:" <<net_Cost <<endl;
}
// Both PriceofStartTime & PriceofLengthofCall are discounted.
// because of start_time and call_length
else if (start_time >=1800 || start_time<800)
if (Length_of_call>60)
{ PriceofStartTime =(start_time*federal_tax);
PriceofLengthofCall=(Length_of_call*regular_rate);
gross_Cost = PriceofStartTime + PriceofLengthofCall;
cout << "Gross cost: "<<gross_Cost<<endl;
net_Cost= (PriceofStartTime*with_discount)+
(PriceofLengthofCall*discount_PerMin);
cout << "Net cost: "<< net_Cost << endl;
}
// No discounts are applicable!
// time and length do not meet discount criteria
else if (start_time<1800 || start_time>800)
if (Length_of_call<60)
{ PriceofStartTime =(start_time*federal_tax);
PriceofLengthofCall=(Length_of_call*regular_rate);
gross_Cost= PriceofStartTime + PriceofLengthofCall;
cout << "Gross cost: "<<gross_Cost<<endl;
net_Cost = gross_Cost ;
cout << "Net cost: "<< net_Cost << endl;
}
return 0;
}
|