The question is about long-distance carrier charges Starting time ofcall Rate pe
ID: 3618592 • Letter: T
Question
The question is about long-distance carrier charges Starting time ofcall Rate per Minute 00:00 -06:59 $0.12 07:00 -19:00 0.55 19:01 -23:59 0.35 Write a program that asks for the starting time and the numberof minutes of the call, and displays the charges. The programshould ask for the time to be entered as a floating-point number inthe form HH.MM. For example, 07:00 hour will be entered as 07.00,and 16:28 hours will be entered as 16.28. Input Validation: The program should not accept times that aregreater than 23:59. Also, no number whose last two digits aregreater than 59 should be accepted. Hint: Assuming num is afloating-point variable, the following expression will give you itsfractional part: num - static_cast<int>(num) This is the problem listed in the book. I don'tunderstand how to keep the last two digits from going over59. Can you please write out the code so I can see where I ammissing the information needed? The question is about long-distance carrier charges Starting time ofcall Rate per Minute 00:00 -06:59 $0.12 07:00 -19:00 0.55 19:01 -23:59 0.35 Write a program that asks for the starting time and the numberof minutes of the call, and displays the charges. The programshould ask for the time to be entered as a floating-point number inthe form HH.MM. For example, 07:00 hour will be entered as 07.00,and 16:28 hours will be entered as 16.28. Input Validation: The program should not accept times that aregreater than 23:59. Also, no number whose last two digits aregreater than 59 should be accepted. Hint: Assuming num is afloating-point variable, the following expression will give you itsfractional part: num - static_cast<int>(num) This is the problem listed in the book. I don'tunderstand how to keep the last two digits from going over59. Can you please write out the code so I can see where I ammissing the information needed?Explanation / Answer
#include<iostream>
using namespace std;
void main()
{ float time,callTime,minutes,cost,chrs,cmin;
int total,hours;
//inputting time
cout<<" Enter time : ";
cin>>time;
hours=static_cast<int>(time);
//fraction part
minutes=(time-static_cast<int>(time))*100;
cout<<"Enter call minutes:";
cin>>callTime;
chrs=static_cast<int>(callTime);
cmin=(callTime-static_cast<int>(callTime))*100;
//input vallidation
if(hours<=24)
{
if(minutes<=59)
{
//Time call b/w 0-6.00
if(time>=0 && time<=6.59)
{
total=(cmin+(chrs*60));
cost=total*0.12;
}
//Time call b/w 7-19
else if(time>=7 && time<=19)
{
total=(cmin+(chrs*60));
cost=total*0.55;
}
//Time call b/w 19-23.59
else if(time>=19 && time<=23.59)
{
total=(cmin+(chrs*60));;
cost=total*0.35;
}
cout<<" Telephone Call Charges: $"
<<cost<<endl;
}
else
cout<<"Invalid minutes"<<endl;
}
else
cout<<"Invalid hours"<<endl;
//pause system for a while
system("pause");
}//end main
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.