Join 137,394 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,133 people online right now. Registration is fast and FREE... Join Now!
I need to be able to enter in a start time based on a 24 hour clock, and the length of time. It will calculate the gross cost (before any discounts),and net cost. It was working until I entered in the 2nd "Else If" statement, but the time frames I entered are valid. I'm not sure what I'm missing...Any help or comments are appreciated.
for a start the = (an assignment) in statement if((startTime<0 && startTime>=2401)||(lengthTime=0)) should be == (test equality), i.e. if((startTime<0 && startTime>=2401)||(lengthTime==0))
I am now having the output give me when I input 700 as my Start time, and 20 as my length of time it give me the output "gross cost 2.00 Invalid Data Entered!"
it is bypassing my else if statement for afterhours calls?
did not make a difference, It still will not give me my Net Cost. I looked to see if I might have forgotten anything else, but did not see anything missing.
thanks for the help so far!! still new to programming
could it be because of where I have this statement?
Here is the message I am getting when I use the f5 (go):
The thread 0x34C has exited with code 0 (0x0). The program 'C:\Documents and Settings\xxxx\Desktop\Lab3assignments\Harford Telephone Company\Debug\harfod_Tele.exe' has exited with code 0 (0x0).
This post has been edited by jona431: 29 Oct, 2006 - 02:56 PM
Okay well first of all, your loop is testing true no matter what at the moment when it hits ||(lengthTime == 0)) because the value of lengthTime was never modified so it is zero, meaning no matter what the user enters as the start time, this will always evaluate to true. It should be changed to && instead.
Second you may want to allow the user to enter the length of the call before you enter the if statement, otherwise testing for the length is useless.
Let me see what you got after that and we'll see what else may be amiss if anything.
netCost=(grossCost-sixtyMinDisc)+(grossCost*taxRate); /*Calcualting Net Cost discounted*/ printf("\nNet Cost%5.2f\n",netCost); } /*Calcualting After Hours Calling no Afet hours discount only*/ else if ((startTime>=1800)&&(startTime<800)&&(lengthTime<60)) { afterHours_call=(grossCost*afterHours_call);
netCost=(grossCost-afterHours_call*taxRate); printf("Net Cost%5.2f",netCost); } /*Calcualting After Hours Calling no After hours discount & over 60min discount*/ else if ((startTime>=1800)&&(startTime<800)&&(lengthTime>60)) { sixtyMinDisc=(grossCost*sixtyMinDisc);
afterHours_call=(grossCost*afterHours_call);
netCost=(grossCost-afterHours_call)+(grossCost*sixtyMinDisc)+(grossCost*taxRate); printf("Net Cost%5.2f",netCost); } else printf("Invalid Data Entered");
Not sure if I should add an else to the 2nd if statement..Could that be causing one of my issues. printf("Hardford Telephone Company\n"); printf("\nStart Time:"); scanf("%f",&startTime); printf("\nLength of Time:"); scanf("%f",&lengthTime); if((startTime<0 && startTime>=2401)&&(lengthTime=0)) { grossCost=(lengthTime*reg_Rate); printf("\nGross Cost%5.2f\n",grossCost); } /* Calculating regular rate call w/ no discount */ if ((startTime >=800)&&(startTime<1800)&&(lengthTime<60)) {