Hi can any one help me with my if / else statement,
I have an assignment which has to give discounts to phone calls depending on the time of call or the day. Here are the discounts
Starting Time--------------Monday to Friday-------------Saturday and Sunday
Before 8am-----------------40% discount-----------------60% discount
8am to 4:59pm--------------Regular charge rate----------60% discount
5pm to 10:59pm-------------30% discount-----------------60% discount
11pm to 7:59am-------------40% discount-----------------60% discount
My program throws out two discounts, where am i going wrong,,,
Any suggestions / help most welcome.
Thanks
steve
below is my code
//This program will output a statement
//Created by
//Date
#include <iostream>
using namespace std;
using namespace std;
char day, chday, pound=156, awnser ;
int call_start, call_end, call_dur, counter, bad_time, total_calls;
float dis_zero, dis_six, dis_three, dis_four, fullcost, discount, end_total, next_call;
double call_start_hrs, call_start_min,call_end_hrs,call_end_min, tot_call_start_min, tot_call_end_min, duration;
bool ans, another;
float input_data()
{
day=false;
cout<<"\n\n";
cout<<"=============================================================";
cout<<"\n\n";
cout<< "****** Enter Day of Call ******";
cout<<"\n\n";
cout<<"\n\n";
cout<<"Please enter day...E.cxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
cout<<"\n\n";
cout<<"M = Monday";
cout<<"\n\n";
cout<<"U = Tuesday";
cout<<"\n\n";
cout<<"W = Wensday";
cout<<"\n\n";
cout<<"T = Thursday";
cout<<"\n\n";
cout<<"F = Friday";
cout<<"\n\n";
cout<<"A = Saturday";
cout<<"\n\n";
cout<<"S = Sunday";
cout<<"\n\n";
cout<<"\n\n";
while (!day){
//This proceedure validateds the inputed day is correct
cin>>chday;
cout<<"\n\n";
if((chday=='M')||(chday=='U')||(chday=='W')||(chday=='T')||(chday=='F')||(chday=='A')||(chday=='S'))
{
day=true;
}
else
{
day=false;
cout<<"\n\n";
cout<<"!!Error!!...Please Enter A Valid Character";
cout<<"\n\n";
}
}
return 0;
}
float enter_times()
{
cout<<"\n\n";
cout<<"=============================================================";
cout<<"\n\n";
cout<<" ****** Enter Call Times ******";
cout<<"\n\n";
cout<<"\n\n";
cout<<"Please Enter Start Time Of Your Call ";
cin>>call_start;
cout<<"\n\n";
cout<<"\n\n";
cout<<"Please Enter End Time Of Your Call ";
cin>>call_end;
cout<<"\n\n";
cout<<"=============================================================";
cout<<"\n\n";
return 0;
}
double calc_min()
{
//This proceedure converts the enterd start and stop times into minuts
call_start_hrs=(call_start/100);
call_start_min=(call_start%100);
tot_call_start_min=((call_start_hrs*60)+call_start_min);
call_end_hrs=(call_end/100);
call_end_min=(call_end%100);
tot_call_end_min=((call_end_hrs*60)+call_end_min);
duration=((tot_call_end_min)-tot_call_start_min);
return 0;
}
float charge_rate()
{
if (duration<=3)
{
fullcost=(1.50);
}
else
{
fullcost=((0.30)*(duration));
}
return 0;
}
float output_data()
{
switch(chday)
//This swich satement prints out on the screen the day the call was made on
{
case 'M':
cout<<"Your Call was made on a Monday";
cout<<"\n\n";
break;
case 'U':
cout<<"Your Call was made on a Tuesday";
cout<<"\n\n";
break;
case 'W':
cout<<"Your Call was made on a Wensday";
cout<<"\n\n";
break;
case 'T':
cout<<"Your Call was made on a Thursday";
cout<<"\n\n";
break;
case 'F':
cout<<"Your Call was made on a Friday";
cout<<"\n\n";
break;
case 'A':
cout<<"Your Call was made on a Saturday";
cout<<"\n\n";
break;
case 'S':
cout<<"Your Call was made on a Sunday";
cout<<"\n\n";
break;
default: cout<<"Error";
}
cout<<" the day your call was made was a " <<chday;
cout<<"\n\n";
cout<<"The Total number of Calls you have made today is [" <<counter++ <<"].";
cout<<"\n\n";
cout<<"Your Call Started At " <<call_start <<" Hundred hours.";
cout<<"\n\n";
cout<<"Your Call Ended At " <<call_end <<" Hundred hours.";
cout<<"\n\n";
cout<<"The Total Duration Of Your Call Is "<<duration <<" Minutes.";
cout<<"\n\n";
cout<<"The Total Cost Of Your Telephone Call Is " <<pound << fullcost;
return 0;
}
float calc_discounts()
{
{
dis_zero=(fullcost*0.00);
dis_three=(fullcost*0.03);
dis_four=(fullcost*0.04);
dis_six=(fullcost*0.06);
if (chday='A'||'S')
{
cout<<"\n\n";
cout<<"The Total Discount Of Your Telephone Call is " <<pound << dis_six<<" 60 per";
cout<<"\n\n";
}
else
if(call_start_hrs<=8)
{
cout<<"\n\n";
cout<<"The Total Discount Of Your Telephone Call is " <<pound << dis_four<<" 40 per ";
cout<<"\n\n";
}
else
if((call_start_hrs>=8)&& (call_end_hrs <=17))
{ //this is working
cout<<"\n\n";
cout<<"The Total Discount Of Your Telephone Call is " <<pound <<dis_zero<<" 0 per";
cout<<"\n\n";
}
else
((call_start_hrs>=17)&&(call_end_hrs<=23));
{ // this is throwing out a 4 % discount???
cout<<"\n\n";
cout<<"The Total Discount Of Your Telephone Call is " <<pound << dis_three<<" 30 per";
cout<<"\n\n";
}
cout<<"\n\n";
end_total=(fullcost - discount);
cout<<" *** The amount you pay, less discount is " <<pound <<end_total;
cout<<"\n\n";
cout<<"============================================================";
cout<<"\n\n";
}
return 0;
}
float another_call()
{
do
{
cout<<"Do you want to make another Call?";
cout<<"\n\n";
cout<< "Type ( Y ) for Yes or ( N ) for No...... ";
cin>>awnser;
cout<<"\n\n";
cout<<"============================================================";
cout<<"\n\n";
if (awnser=='Y')
{
another=true;
ans=true;
}
else
{
cout<<"\n\n";
cout<<"\n\n";
cout<<" Thank you for using the Telephone Call Calculator,,,,,Goodbye";
ans=false;
cout<<"\n\n";
break;
}
}
while(!ans);
return 0;
}
int main()
{
counter=1;
do
{
input_data();
enter_times();
calc_min();
charge_rate();
output_data();
calc_discounts();
another_call();
}
while(awnser=='Y');
system("pause");
return 0;
}