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;
}

Check your code again. You print out the cost in both calc_discounts (line 269) and output_data (line 211). You might want to condense your code a bit, since it's very difficult to sift through. Generally, if it's difficult for us to read your code, it's difficult for you to read your code.

Edited 6 Years Ago by xikkub: n/a

no, that is the fullcost less the discount that prints out in calc_discounts().
i just carnt figure out this issue,

I don't know about you, but the only thing I see printed twice is "The Total Discount Of Your Telephone Call is". Also, your end time input is broken.

Try generalising the program using global variables. instead of using so many cout statements printing the same thing, use one cout and the variables(which will have different values acc to time and day). use a func to calc the values of variables.
EX

char day[10];
switch(chday)
{
 case 'M':
				day = "Monday";
				break;
		case 'U':
				day = "tuesday"
				cout<<"\n\n";
				break;
		case 'W':
				day = "wednesday"
				break;
		
		default: cout<<"Error";
 
}
cout << "The Call Was Made On " << day << endl ;

Edited 6 Years Ago by Jason Giggs: n/a

Following standard programming conventions, it's undesirable to use global variables where locals will do. Use less output and text formatting. Remove unnecessary cout lines and simplify your code before adding final touches. If you simplify the code and learn how to pass data to a function, you can make your work much easier.

Also, Jason, declaring a character array of 10 is NOT a good idea in this case since the day name length can vary. If anything, I'd use a dynamic character array.

Edited 6 Years Ago by xikkub: n/a

Comments
Was thinking the same thing.

Following standard programming conventions, it's undesirable to use global variables where locals will do. Use less output and text formatting. Remove unnecessary cout lines and simplify your code before adding final touches. If you simplify the code and learn how to pass data to a function, you can make your work much easier.

Also, Jason, declaring a character array of 10 is NOT a good idea in this case since the day name length can vary. If anything, I'd use a dynamic character array.

I just wanted to demonstrate use of array, size needn't be fixed. I was giving an idea how cout can be reduced.
also, thanks for the fact about the global variables, i'll keep that in mind.

This question has already been answered. Start a new discussion instead.