Thread: Sorry, need help again

  1. #1
    Registered User
    Join Date
    Jan 2010
    Posts
    16

    Sorry, need help again

    Need help once more. The program stops after the fist if statement. I am drawing a blank.

    I am not understanding how to check the variable also. I am not good at this programming.

    Code:
    printf ("------------------------------------------\n");
    printf ("Tax Calc\n\n");
    printf ("Purchase Amount:  ");
    int puramnt;
    scanf ("%f", &puramnt);
    printf ("\n");
    if (puramnt <= 0 || puramnt >= 'A')
          {
                printf ("Please enter a number for Purchase Amount.\n");
                    }
     else
          {
    /*change to add selection for store number*/
    printf ("Please select store location:\n");
    printf ("1) decon\n");
    printf ("2) Enry\n");
    printf ("3) Lafeyette\n");
    printf ("4) Exit\n\n");
    int opt2;
    scanf ("%d", &opt2);
    printf ("\t\t\tTax\tSales\n");
    printf ("Store\t\t\tRate\tTax\n");
    printf ("------------------------------------------\n");
    /*Compute Sales Tax*/
    if (opt2 == 1)
    {
        float deconaxrate = 7.25;
    float tottax = (puramnt*decontaxrate)/100;
    printf ("Decon\t\t\t7.25\t%.2f\n",tottax);
    }
    else if (opt2 == 2)
    {
    float enrytaxrate = 7.50;
    float tottax2 = (puramnt*enrytaxrate)/100;
    printf ("Enry\t\t7.50\t%.2f\n",tottax2);
    }
    else if (opt2 == 3)
    {
    float lafayettetaxrate = 7.75;
    float tottax3 = (puramnt*lafayettetaxrate)/100;
    printf ("Lafayette\t\t7.75\t%.2f\n",tottax3);
    }
    else if (opt2 >4 || opt2 < 1)
    {
         printf ("Please enter a number between 1 - 4.");
         }
    else (opt2 == 4);
    return 0;
    }
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    What is it supposed to do? What are you entering for your first scanf? Oh, and you're probably hitting the "there's a newline in my buffer, so it's skipping my second scanf" issue. See the FAQ.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jan 2010
    Posts
    16
    It is supposed to be able to enter an amount, then select a location and figure sales tax amount and total sale.

  4. #4
    Registered User
    Join Date
    Jan 2010
    Posts
    16
    I have changed the code to have a sitch break and I am having trouble with case 2 recognizing. I get an error "jump to case " and cross initialization of the tax rates.

    Code:
    printf ("Purchase Amount:  ");
    int puramnt;
    scanf ("%s", &puramnt);
    printf ("\n");
    if (puramnt <=0.0 || puramnt >='A')
    
          {
                printf ("Please enter a number for Purchase Amount.\n");
                    }
    int opt2;
    while (opt2 !=4)
          {
    /*change to add selection for store number*/
    printf ("Please select store location:\n");
    printf ("1) decon\n");
    printf ("2) Enry\n");
    printf ("3) Lafayette\n");
    printf ("4) Exit\n\n");
    scanf ("%d", &opt2);
    printf ("\t\t\tTax\tSales\n");
    printf ("Store\t\t\tRate\tTax\n");
    printf ("------------------------------------------\n");
    switch (opt2)
    {
    
    /*Compute Sales Tax*/
    case (1) :
    float decontaxrate = 7.25;
    float tottax = (puramnt*decontaxrate)/100;
    printf ("decon\t\t\t7.25\t%.2f\n",tottax);
    break;
    case (2) :
    float Enry\taxrate = 7.50;
    float tottax2 = (puramnt*Enry\taxrate)/100;
    printf ("Enry\\t\t7.50\t%.2f\n",tottax2);
    break;
    case (3):
    float Lafayettetaxrate = 7.75;
    float tottax3 = (puramnt*Lafayettetaxrate)/100;
    printf ("Lafayette\t\t7.75\t%.2f\n",tottax3);
    break;
    case (4):exit(1);
    break;
    default : 
    printf ("Please enter a number between 1 - 4.");
    break;
    } 
    while ((opt2 <1) || (opt2 >4));
    return 0;
    }

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    These aren't the same variable names as you used previously. They're very dodgy because they contain a different name and include an unwanted '\' char, as well. Note also that "Enry" is not "Entry", and don't you want to use the spelling with a t in it?

    Code:
    float Enry\taxrate = 7.50;
    float tottax2 = (puramnt*Enry\taxrate)/100;
    That would be the first thing I'd check into. If you still don't find it, post up your whole program or an example showing the problem, so I can run it.

  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You need to seriously indent the code. If you haven't already in your real code, then that should be your number #1 priority.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Quote Originally Posted by Elysia View Post
    You need to seriously indent the code. If you haven't already in your real code, then that should be your number #1 priority.
    I know; I was working on the theory that his or her compiler looked at the formatting and jabbed its eyes out to keep from seeing any more after the first if()...

    Just kidding....compilers don't have eyes...

    But if they did...
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    ^^^ Compilers jabbing their eyes out - ROFL!!

    Thanks, Jeff.

Popular pages Recent additions subscribe to a feed