I am a C++ beginner and I am working on a C++ project that calucates the phone bill.
I got stuck on how to make every 60 minutes into one hour.. Like if the user enter 1000 (10:00) and it asks for the length of your phone call, if the user enters 70, the program has to print out the result time (end_time) 1110
here's my program, hope you guys can help me out!!
Thanks alot!
[CODE=cpp]#include<iostre am.h>
main()
{
int start_time;
int length;
int end_time;
double gross_cost ;
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;
cout << "What was the start time of your phone call? Write as 1900 instead of 7:00 PM\n";
cin >> start_time;
//Any call started at or after 7:00 P.M. (1900 hours) but before 8:00 A.M. (0800 hours) is discounted 60 percent.
if (start_time >= 1900 || start_time <= 800)
{
time_discount = (length * 0.25) * 0.6;
}
//Asking for the length.
cout << "What was the length of your phone call in minutes?\n";
cin >> length;
//make time look nice
length_min = length % 100;
length_hour = length / 100;
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;
//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 = 0.3 * (gross_cost - time_discount);
}
// if time doesn't apply
else(length <=21);
{
length_discount = 0.3 * gross_cost;
}
//calculations
end_time = start_time + length;
total_discounts = time_discount + length_discount ;
gross_cost = length * 0.25;
time_discount = gross_cost * 0.6;
gross_cost = total_discounts + (tax + net_cost);
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 << '\n';
cout.unsetf(ios ::scientific);
cout << "Gross Cost: " << length * 0.25 << '\n';
cout << "Time Discount: " << (length * 0.25) * 0.6 << '\n';
cout << "Length Discount: " << length_discount << '\n';
cout << "Total Discounts: " << time_discount + length_discount << '\n';
cout << "Tax: " << (length * 0.25) - (time_discount + length_discount ) * 0.08 << '\n';
cout << "Net Cost: " << (length * 0.25) + tax - total_discounts << '\n';
return 0;
}[/CODE]
I got stuck on how to make every 60 minutes into one hour.. Like if the user enter 1000 (10:00) and it asks for the length of your phone call, if the user enters 70, the program has to print out the result time (end_time) 1110
here's my program, hope you guys can help me out!!
Thanks alot!
[CODE=cpp]#include<iostre am.h>
main()
{
int start_time;
int length;
int end_time;
double gross_cost ;
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;
cout << "What was the start time of your phone call? Write as 1900 instead of 7:00 PM\n";
cin >> start_time;
//Any call started at or after 7:00 P.M. (1900 hours) but before 8:00 A.M. (0800 hours) is discounted 60 percent.
if (start_time >= 1900 || start_time <= 800)
{
time_discount = (length * 0.25) * 0.6;
}
//Asking for the length.
cout << "What was the length of your phone call in minutes?\n";
cin >> length;
//make time look nice
length_min = length % 100;
length_hour = length / 100;
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;
//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 = 0.3 * (gross_cost - time_discount);
}
// if time doesn't apply
else(length <=21);
{
length_discount = 0.3 * gross_cost;
}
//calculations
end_time = start_time + length;
total_discounts = time_discount + length_discount ;
gross_cost = length * 0.25;
time_discount = gross_cost * 0.6;
gross_cost = total_discounts + (tax + net_cost);
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 << '\n';
cout.unsetf(ios ::scientific);
cout << "Gross Cost: " << length * 0.25 << '\n';
cout << "Time Discount: " << (length * 0.25) * 0.6 << '\n';
cout << "Length Discount: " << length_discount << '\n';
cout << "Total Discounts: " << time_discount + length_discount << '\n';
cout << "Tax: " << (length * 0.25) - (time_discount + length_discount ) * 0.08 << '\n';
cout << "Net Cost: " << (length * 0.25) + tax - total_discounts << '\n';
return 0;
}[/CODE]
Comment