As a beginner, I am working on a project that calculates the telephone bill. Thank you all, my program is great.. but I got another problem because my teacher was trying to trick me with this..
that he enter 0100, he didn't enter 100 so the program's calculation is totally wrong.
I have tried to use if statements, it works when entering 0100 but it does not work when entering 1000, it got some wrong calculation.. Everytime I enter 0 before the time (like 0800) the program doesn't work properly.. I don't know why!!
Can you guys help me out with this? I am so confused.
[CODE=cpp]#include<iostre am.h>
#include<iomani p.h>
int main()
{
int start_time;
int length;
int end_time;
double gross_cost = length * 0.25;
double length_discount ;
double total_discounts ;
double tax;
double net_cost;
double time_discount;
int length_min, length_hour;
int end_min, end_hour;
int call_hour, call_min;
int i;
//Any call started at or after 7:00 P.M. (1900 hours) but before 8:00 A.M. (0800 hours) is discounted 60 percent.
cout << "What was the start time of your phone call? Write as 1900 instead of 7:00 PM\n";
cin >> start_time;
//above is the question asking for the time, I just can't enter 0 before the hour time (Like 0800), otherwise it gets problems..
//Asking for the length.
cout << "What was the length of your phone call in minutes?\n";
cin >> length;
gross_cost = length * 0.25;
if (start_time >= 1900 || start_time <= 800)
{
time_discount = (gross_cost) * 0.6;
}
//make time look nice
length_min = length % 60;
length_hour = length / 60;
call_min = start_time % 100;
call_hour = start_time / 100;
end_hour = call_hour + length_hour;
end_min = call_min + length_min;
if (end_min >= 60)
{
end_hour++;
}
//end_time = (call_hour + length_hour) * (100) + end_min;
end_time = (end_hour) * (100) + end_min;
//Any call at least 20 minutes long receives a 30 percent discount on its cost (after any other discount is subtracted).
gross_cost = length * 0.25;
if(length >=20)
{
length_discount = (gross_cost - time_discount) * 0.3;
}
// if time doesn't apply
else
{
length_discount = 0.3 * gross_cost;
}
//calculations
total_discounts = time_discount + length_discount ;
gross_cost = length * 0.25;
tax = (gross_cost - total_discounts ) * 0.08;
net_cost = gross_cost + tax - total_discounts ;
// Print the result.
cout << "Start Time: " << start_time << '\n';
cout << "End Time: " << end_time << '\n';
cout << "Length: " << length_hour << ":" << length_min << '\n';
cout.setf(ios:: fixed);
cout << "Gross Cost: " << "$" << setprecision(2) << length * 0.25 << '\n';
cout << "Time Discount: " << setprecision(2) << "$" << time_discount << '\n';
cout << "Length Discount: " << "$" << length_discount << '\n';
total_discounts = time_discount + length_discount ;
cout << "Total Discounts: " << "$" << total_discounts << '\n';
tax = (gross_cost - total_discounts ) * 0.08;
cout.setf(ios:: fixed);
cout << "Tax: " << setprecision(2) << "$" << tax << '\n';
net_cost = (gross_cost + tax) - (total_discount s);
cout.setf(ios:: fixed);
cout << "Net Cost: " << setprecision(2) << "$" << net_cost << '\n';
return 0;
}[/CODE]
that he enter 0100, he didn't enter 100 so the program's calculation is totally wrong.
I have tried to use if statements, it works when entering 0100 but it does not work when entering 1000, it got some wrong calculation.. Everytime I enter 0 before the time (like 0800) the program doesn't work properly.. I don't know why!!
Can you guys help me out with this? I am so confused.
[CODE=cpp]#include<iostre am.h>
#include<iomani p.h>
int main()
{
int start_time;
int length;
int end_time;
double gross_cost = length * 0.25;
double length_discount ;
double total_discounts ;
double tax;
double net_cost;
double time_discount;
int length_min, length_hour;
int end_min, end_hour;
int call_hour, call_min;
int i;
//Any call started at or after 7:00 P.M. (1900 hours) but before 8:00 A.M. (0800 hours) is discounted 60 percent.
cout << "What was the start time of your phone call? Write as 1900 instead of 7:00 PM\n";
cin >> start_time;
//above is the question asking for the time, I just can't enter 0 before the hour time (Like 0800), otherwise it gets problems..
//Asking for the length.
cout << "What was the length of your phone call in minutes?\n";
cin >> length;
gross_cost = length * 0.25;
if (start_time >= 1900 || start_time <= 800)
{
time_discount = (gross_cost) * 0.6;
}
//make time look nice
length_min = length % 60;
length_hour = length / 60;
call_min = start_time % 100;
call_hour = start_time / 100;
end_hour = call_hour + length_hour;
end_min = call_min + length_min;
if (end_min >= 60)
{
end_hour++;
}
//end_time = (call_hour + length_hour) * (100) + end_min;
end_time = (end_hour) * (100) + end_min;
//Any call at least 20 minutes long receives a 30 percent discount on its cost (after any other discount is subtracted).
gross_cost = length * 0.25;
if(length >=20)
{
length_discount = (gross_cost - time_discount) * 0.3;
}
// if time doesn't apply
else
{
length_discount = 0.3 * gross_cost;
}
//calculations
total_discounts = time_discount + length_discount ;
gross_cost = length * 0.25;
tax = (gross_cost - total_discounts ) * 0.08;
net_cost = gross_cost + tax - total_discounts ;
// Print the result.
cout << "Start Time: " << start_time << '\n';
cout << "End Time: " << end_time << '\n';
cout << "Length: " << length_hour << ":" << length_min << '\n';
cout.setf(ios:: fixed);
cout << "Gross Cost: " << "$" << setprecision(2) << length * 0.25 << '\n';
cout << "Time Discount: " << setprecision(2) << "$" << time_discount << '\n';
cout << "Length Discount: " << "$" << length_discount << '\n';
total_discounts = time_discount + length_discount ;
cout << "Total Discounts: " << "$" << total_discounts << '\n';
tax = (gross_cost - total_discounts ) * 0.08;
cout.setf(ios:: fixed);
cout << "Tax: " << setprecision(2) << "$" << tax << '\n';
net_cost = (gross_cost + tax) - (total_discount s);
cout.setf(ios:: fixed);
cout << "Net Cost: " << setprecision(2) << "$" << net_cost << '\n';
return 0;
}[/CODE]
Comment