equations

This is realy doing my head in now, please help.
I have managed to get most of my program running now but my output costs are not working; why?

[code]#include
#include



char day, chday,chstart[5],chend[5], answer;
int starttime, Endtime, callcount;
float tothrs, totmins, cost,subcost, dis, net;
bool another=true, ans=true, ok=false;


// convert function is called to change the times from characters to interger

void clear()
{

}

void getinfo()
{
callcount = (callcount+1);
cout<<""<<endl;
cout<<"---- Please Select The Appropriate Code ----"<<endl;
cout<<""<<endl;
cout<<"---------------For Your Day------------------"<<endl;
cout<<""<<endl;
cout<<""<<endl;
cout<<"
M - Monday
U - Tuesday
W - Wednesday
T - Thursday
F - Friday
A - Saturday
S - Sunday";
day = false;

// 'while' loop to check on correct day

while (!day)
{
cout<<""<<endl;
cout<<""<<endl;
cout<<"Please select the correct day and enter the code"<<endl;
cout<<""<<endl;
cout<<""<<endl;
cin>>chday;
if ((chday == 'S')|| (chday == 'M')||(chday == 'U')|| (chday == 'W')||(chday == 'T')|| (chday == 'F')||(chday == 'A'))
{
day = true;

cout <<endl;
}
else
{
day = false;
cout << " You have entered an invalid day please re-enter your day";
}
}
}

void outday()
{
switch (chday)
{
case 'M':
cout<<""<<endl;
cout<<""<<endl;
cout<<" You have choosen Monday";
cout<<""<<endl;
cout<<""<<endl;
break;

case 'U':
cout<<""<<endl;
cout<<""<<endl;
cout<<" You have choosen Tuesday";
cout<<""<<endl;
cout<<""<<endl;
break;

case 'W':
cout<<""<<endl;
cout<<""<<endl;
cout<<" You have choosen Wednesday";
cout<<""<<endl;
cout<<""<<endl;
break;

case 'T':
cout<<""<<endl;
cout<<""<<endl;
cout<<" You have choosen Thursday";
cout<<""<<endl;
cout<<""<<endl;
break;

case 'F':
cout<<""<<endl;
cout<<""<<endl;
cout<<" You have choosen Friday";
cout<<""<<endl;
cout<<""<<endl;
break;

case 'A':
cout<<""<<endl;
cout<<""<<endl;
cout<<" You have choosen Saturday";
cout<<""<<endl;
cout<<""<<endl;
break;

case 'S':
cout<<""<<endl;
cout<<""<<endl;
cout<<" You have choosen Sunday";
cout<<""<<endl;
cout<<""<<endl;
break;
}

}

int convert(char time[5])
{
int time_mins;
int int_time[4];

int_time[0]=time[0]-'0';
int_time[1]=time[1]-'0';
int_time[2]=time[2]-'0';
int_time[3]=time[3]-'0';


//Make clock changes here instead of further down(10->6)

time_mins = int_time[0]* 600 + int_time[1] * 60 + int_time[2] * 10 + int_time[3];
return time_mins;
}

void calctime ()
{
cout<<""<<endl;
cout<<" Please enter the start time of your call"<<endl;
cout<<""<<endl;
cin>> chstart;
cout<<""<<endl;

starttime = convert(chstart);
cout<<""<<endl;

cout<<""<<endl;

cout<<""<<endl;
cout<<" Please enter the time your call ended"<<endl;
cout<<""<<endl;
cin>> chend;
cout<<""<<endl;

Endtime = convert(chend);
cout<<""<<endl;


totmins = (Endtime - starttime);

tothrs =(totmins / 60);



if (starttime> Endtime)
{
totmins =(totmins + 1440);
}

if (totmins>=600)
{
ok=true;
cout<<"Invalid time, please input again"<<endl;
ok=false;
calctime();

}





}

void discount()
{
cost=totmins-3*0.3+1.5;

if (totmins<=3)
{
cost=1.5;
}

if ((day=='A')||(day=='S'))
{
subcost=cost*.6;
}


else
if
((starttime>=800)&&(Endtime<=1700))
{
subcost=(cost*.0);
}



if ((starttime>1700)&&(Endtime<=2300))
{
subcost=(cost*.3);
}


if ((starttime>2300)&&(Endtime<=759))
{
subcost=(cost*.4);
}

net=(cost-subcost);


cout<<""<<endl;
cout<<" Call start time "<<chstart;
cout<<""<<endl;
cout<<" Call end time "<<chend;
cout<<""<<endl;
cout<<" Your call lasted "<<totmins<<" minutes"<<endl;
cout<<""<<endl;
cout<<" The cost of your call is "<<cost;
cout<<""<<endl;
cout<<" Your discount is "<<subcost;
cout<<""<<endl;
cout<<" The cost of your call including your discount is "<<net;
cout<<""<<endl;

cout<<"====================================================="<<endl;





}

void again()
{
do
{
cout<<"Would you like to run the programme again (Y/N)?";
cin>>answer;
if (answer == 'Y')
{

another=true;
ans=true;
}
else if (answer == 'N')
{
another=false;
ans=true;
}
else
{
cout<<"Invalid selection. Please selected (Y/N)"<<endl;
ans=false;
cout<<""<<endl;

}

cout<<"====================================================="<<endl;
cout<<"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;
}
while(!ans);
}

void main()
{
do
{
clear();
getinfo();
outday();
calctime();
discount();
again();
}
while (another);
cout<<"The number of calls made was "<<callcount;
cout<<""<<endl;
cout<<"Thank You"<<endl;
cout<<" "<<endl;

}
[/code]

Comments

  • Fixed code tags in your post. To preserve the indention of the code when posting, please do like this:

    [leftbr]code[rightbr]
    int main()
    {
    cout << "Hello world!" << endl;
    }
    [leftbr]/code[rightbr]

    To make the code appear like this:

    [code]int main()
    {
    cout << "Hello world!" << endl;
    }[/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion