Im taking my c++ class online, and can't figure out any of my codes. the teacher is literally no help at all, and the other students dont reply on the discussion board, and there are only 2 tutors at my school they seem just as confused by c++ as i am. so if someone could help with some feedback on what im doing wrong?
heres the assignment
Assignment 3.5
Based on a problem from Walter Savitch, Problem Solving with C++: The Object of Programming.
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
My code
i tried using 2 if statements because it didnt seem like it went through everything when i had
if (StartTime<1800 || StartTime<800 && LengthofCall>60)
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 74 75 76 77
|
// Assignment 3.5
//PhoneCompany
#include <iostream>
using namespace std;
int main()
{
int StartTime;
int LengthofCall;
const float fedTax = .04;
const float rate = .35;
const float discount = .05;
const float discountOnMin = .16;
float grossCost;
float PriceofStartTime;
float PriceofLengthofCall;
float netCost;
cout << "Enter start time: "<<endl;
cin >> StartTime;
cout << "Enter length of the call in minutes: "<<endl;
cin >> LengthofCall;
//case 1 PriceofStartTime is discounted
if (StartTime >=1800 || StartTime<800)
if (LengthofCall<60)
{ PriceofStartTime =(StartTime*fedTax);
PriceofLengthofCall=(LengthofCall*rate);
grossCost= PriceofStartTime + PriceofLengthofCall;
cout << "Gross cost: "<<grossCost<<endl;
netCost= (PriceofStartTime*discount) + PriceofLengthofCall;
cout << "Net cost: "<< netCost << endl;
}
//case 2 PriceofLengthofCall is discounted
else if (StartTime<1800 || StartTime>800)
if (LengthofCall>60)
{ PriceofStartTime =(StartTime*fedTax);
PriceofLengthofCall=(LengthofCall*rate);
grossCost= PriceofStartTime + PriceofLengthofCall;
cout << "Gross cost: "<<grossCost<<endl;
netCost= PriceofStartTime + (PriceofLengthofCall*discountOnMin);
cout << "Net cost: "<< netCost << endl;
}
//case 3 Both PriceofStartTime & PriceofLengthofCall
// are discounted
else if (StartTime >=1800 || StartTime<800)
if (LengthofCall>60)
{ PriceofStartTime =(StartTime*fedTax);
PriceofLengthofCall=(LengthofCall*rate);
grossCost= PriceofStartTime + PriceofLengthofCall;
cout << "Gross cost: "<<grossCost<<endl;
netCost= (PriceofStartTime*discount)+
(PriceofLengthofCall*discountOnMin);
cout << "Net cost: "<< netCost << endl;
}
//case 4 Neither PriceofStartTime & PriceofLengthofCall
// are discounted
else if (StartTime<1800 || StartTime>800)
if (LengthofCall<60)
{ PriceofStartTime =(StartTime*fedTax);
PriceofLengthofCall=(LengthofCall*rate);
grossCost= PriceofStartTime + PriceofLengthofCall;
cout << "Gross cost: "<<grossCost<<endl;
netCost=grossCost ;
cout << "Net cost: "<< netCost << endl;
}
system ("PAUSE");
return 0;
}
|
Outputs
case 1
Enter start time:
759
Enter length of the call in minutes:
10
Gross cost: 33.86
Net cost: 5.018
Press any key to continue . . .
case 2
Enter start time:
1300
Enter length of the call in minutes:
100
Press any key to continue . . .
case3
Enter start time:
2322
Enter length of the call in minutes:
67
Gross cost: 116.33
Net cost: 96.632
Press any key to continue . . .
case4
Enter start time:
1300
Enter length of the call in minutes:
10
Press any key to continue . . .