Welcome to Dream.In.Code
Become a C++ Expert!

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!




Not excepting the input for calculating phone calls by time.

2 Pages V  1 2 >  
Reply to this topicStart new topic

Not excepting the input for calculating phone calls by time., receiveing invalid input when I put a valid time in??

jona431
29 Oct, 2006 - 12:55 PM
Post #1

D.I.C Head
**

Joined: 8 Apr, 2006
Posts: 55


My Contributions
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.

CODE
#include <stdio.h>
#include <conio.h>

int main()

{
    float taxRate=.04;
    float reg_Rate=.10;                    
    float sixtyMinDisc=.15;
    float afterHours_call=.50;        
    float startTime=0;
    float lengthTime=0;
    float grossCost=0;
    float netCost=0;
    

    printf("Hardford Telephone Company\n");
    printf("\nStart Time:");
    scanf("%f",&startTime);
    if((startTime<0 && startTime>=2401)||(lengthTime=0))
    {
    printf("\nLength of Time:");
    scanf("%f",&lengthTime);
        
    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))
    {
        netCost=(grossCost*taxRate+grossCost);
        printf("\nNet Cost%5.2f",netCost);
    }
    /* Calculating regular rate call w/ discount */
    else if ((startTime >=800)&&(startTime <1800)&&(lengthTime>60))
    {
        sixtyMinDisc=(grossCost*sixtyMinDisc); /*Calculating Discount*/

        netCost=(grossCost-sixtyMinDisc)+(grossCost*taxRate); /*Calcualting Net Cost discounted*/
        printf("\nNet Cost%5.2f\n",netCost);
    }
    /*Calcualting After Hours Calling */
    else if ((startTime>=1800)&&(startTime<800)&&(lengthTime<60))
    {
        afterHours_call=(grossCost*afterHours_call);

        netCost=(grossCost-afterHours_call*taxRate);
        printf("Net Cost%5.2f",netCost);
    }
    
    else
        printf("Invalid Data Entered");

        getch ();

    return 0;
}

User is offlineProfile CardPM
+Quote Post

horace
RE: Not Excepting The Input For Calculating Phone Calls By Time.
29 Oct, 2006 - 01:16 PM
Post #2

D.I.C Addict
Group Icon

Joined: 25 Oct, 2006
Posts: 573



Thanked: 4 times
Dream Kudos: 50
My Contributions
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))
User is offlineProfile CardPM
+Quote Post

jona431
RE: Not Excepting The Input For Calculating Phone Calls By Time.
29 Oct, 2006 - 01:24 PM
Post #3

D.I.C Head
**

Joined: 8 Apr, 2006
Posts: 55


My Contributions
Got it..thanks smile.gif

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?
User is offlineProfile CardPM
+Quote Post

horace
RE: Not Excepting The Input For Calculating Phone Calls By Time.
29 Oct, 2006 - 01:35 PM
Post #4

D.I.C Addict
Group Icon

Joined: 25 Oct, 2006
Posts: 573



Thanked: 4 times
Dream Kudos: 50
My Contributions
should you have an else before
/* Calculating regular rate call w/ no discount */
if ((startTime >=800)&&(startTime<1800)&&(lengthTime<60))
User is offlineProfile CardPM
+Quote Post

jona431
RE: Not Excepting The Input For Calculating Phone Calls By Time.
29 Oct, 2006 - 01:50 PM
Post #5

D.I.C Head
**

Joined: 8 Apr, 2006
Posts: 55


My Contributions
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 smile.gif

could it be because of where I have this statement?

grossCost=(lengthTime*reg_Rate);
printf("\nGross Cost%5.2f\n ",grossCost);

I was trying to avoid repetitive typing?

This post has been edited by jona431: 29 Oct, 2006 - 01:52 PM
User is offlineProfile CardPM
+Quote Post

jona431
RE: Not Excepting The Input For Calculating Phone Calls By Time.
29 Oct, 2006 - 02:46 PM
Post #6

D.I.C Head
**

Joined: 8 Apr, 2006
Posts: 55


My Contributions
ok, here is an update of what I have so far. For some reason I cannot get an output of the "Net Cost". Any help please..Thanks

CODE
#include <stdio.h>
#include <conio.h>

int main()

{
    float taxRate=.04;
    float reg_Rate=.10;                    
    float sixtyMinDisc=.15;
    float afterHours_call=.50;        
    float startTime=0;
    float lengthTime=0;
    float grossCost=0;
    float netCost=0;
    

    printf("Hardford Telephone Company\n");
    printf("\nStart Time:");
    scanf("%f",&startTime);
    if((startTime<1 && startTime>=2401)||(lengthTime==0))
    {
    printf("\nLength of Time:");
    scanf("%f",&lengthTime);
        
    grossCost=(lengthTime*reg_Rate);
        printf("\nGross Cost%5.2f\n ",grossCost);
    }
    /* Calculating regular rate call w/ no discount */
    else if ((startTime >=800)&&(startTime<1800)&&(lengthTime<60))
    {
        netCost=(grossCost*taxRate+grossCost);
        printf("\nNet Cost%5.2f",netCost);
    }
    /* Calculating regular rate call w/ discount */
    else if ((startTime >=800)&&(startTime <1800)&&(lengthTime>60))
    {
        sixtyMinDisc=(grossCost*sixtyMinDisc); /*Calculating Discount*/

        netCost=(grossCost-sixtyMinDisc)+(grossCost*taxRate); /*Calcualting Net Cost discounted*/
        printf("\nNet Cost%5.2f\n",netCost);
    }
    /*Calcualting After Hours Calling */
    else if ((startTime>=1800)&&(startTime<800)&&(lengthTime<60))
    {
        afterHours_call=(grossCost*afterHours_call);

        netCost=(grossCost-afterHours_call*taxRate);
        printf("Net Cost%5.2f",netCost);
    }
    
    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");

        getch ();

    return 0;
}


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
User is offlineProfile CardPM
+Quote Post

Antiokus
RE: Not Excepting The Input For Calculating Phone Calls By Time.
29 Oct, 2006 - 04:26 PM
Post #7

D.I.C Head
**

Joined: 6 Sep, 2006
Posts: 127



Thanked: 1 times
My Contributions
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.
User is offlineProfile CardPM
+Quote Post

jona431
RE: Not Excepting The Input For Calculating Phone Calls By Time.
29 Oct, 2006 - 04:48 PM
Post #8

D.I.C Head
**

Joined: 8 Apr, 2006
Posts: 55


My Contributions
Is this what you meant?

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

This post has been edited by jona431: 29 Oct, 2006 - 04:49 PM
User is offlineProfile CardPM
+Quote Post

Antiokus
RE: Not Excepting The Input For Calculating Phone Calls By Time.
29 Oct, 2006 - 05:14 PM
Post #9

D.I.C Head
**

Joined: 6 Sep, 2006
Posts: 127



Thanked: 1 times
My Contributions
That would be it. So now its not going to always test positive on that If statement. Now is it still doing anything unwanted?
User is offlineProfile CardPM
+Quote Post

jona431
RE: Not Excepting The Input For Calculating Phone Calls By Time.
29 Oct, 2006 - 05:45 PM
Post #10

D.I.C Head
**

Joined: 8 Apr, 2006
Posts: 55


My Contributions
now it's not giving me the gross cost or the net cost (netcost is giving me 0.00).

Here is the updated code

CODE
#include <stdio.h>
#include <conio.h>

int main()

{
    double taxRate=.04;
    double reg_Rate=.10;                    
    double sixtyMinDisc=.15;
    double afterHours_call=.50;        
    float startTime=0;
    float lengthTime=0;
    float grossCost=0;
    float netCost=0;
    

    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))
    {
        netCost=(grossCost*taxRate+grossCost);
        printf("\nNet Cost%5.2f",netCost);
    }
    /* Calculating regular rate call w/ discount */
    else if ((startTime >=800)&&(startTime <1800)&&(lengthTime>60))
    {
        sixtyMinDisc=(grossCost*sixtyMinDisc); /*Calculating Discount*/

        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");

        getch ();
    return 0;
}

User is offlineProfile CardPM
+Quote Post

jona431
RE: Not Excepting The Input For Calculating Phone Calls By Time.
29 Oct, 2006 - 06:32 PM
Post #11

D.I.C Head
**

Joined: 8 Apr, 2006
Posts: 55


My Contributions
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))
{
User is offlineProfile CardPM
+Quote Post

monolyth
RE: Not Excepting The Input For Calculating Phone Calls By Time.
29 Oct, 2006 - 06:48 PM
Post #12

New D.I.C Head
*

Joined: 29 Oct, 2006
Posts: 2


My Contributions
your grossCost is never calculated because your if statement
CODE
if((startTime<0 && startTime>=2401)&&(lengthTime=0))

is never executed, your start time cannot be both less than zero and >= 2401

it seems to me that you DONT want your code to run under those conditions..
you can try to change it to
CODE
if((startTime>0 && startTime<2401)&&(lengthTime>0))


This post has been edited by monolyth: 29 Oct, 2006 - 06:57 PM
User is offlineProfile CardPM
+Quote Post

2 Pages V  1 2 >
Reply to this topicStart new topic
Time is now: 12/5/08 02:41AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month