Parce Error Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phxgirl24
    New Member
    • Aug 2007
    • 4

    Parce Error Help

    Can anyone tell me why this won't compile?


    #include <stdio.h>
    #include <ctype.h>

    void main ()
    {

    /* Variables defined with corresponding tax rates. */
    float fTaxRateDelMar = .0725;
    float fTaxRateEncinit as = .075;
    float fTaxRateLaJolla = .0775;

    /* Variable defined for user inputed dollar amount to be taxed.*/
    float fDollarAmount = 0.0;
    printf("\nWelco me to Kudler Fine Foods.\n");
    printf("\nPleas e enter the subtotal to be taxed: ");
    scanf ("%f", &fDollarAmount) ;


    /* Check validity of user input (number) - return if input is invalid, continue if input is valid */
    int i = isdigit(fDollar Amount);
    while i==0
    {
    printf("\nPleas e enter a valid number: ");
    scanf ("%f", &fDollarAmount) ;
    int i = isdigit(fDollar Amount);
    }

    /* Calculation variables defined and calculations accomplished. */
    float fSalesTaxDelMar = fDollarAmount * fTaxRateDelMar;
    float fSalesTaxEncini tas = fDollarAmount * fTaxRateEncinit as;
    float fSalesTaxLaJoll a = fDollarAmount * fTaxRateLaJolla ;
    float fTotalSaleDelMa r = fDollarAmount + fSalesTaxDelMar ;
    float fTotalSaleEncin itas = fDollarAmount + fSalesTaxEncini tas;
    float fTotalSaleLaJol la = fDollarAmount + fSalesTaxLaJoll a;

    /* Print statements to display the Sales Tax and Total Sale values. */
    printf("\nThe sales tax on $%i at the Del Mar store is: $%.2f\n", fDollarAmount, fSalesTaxDelMar );
    printf("\nThe sales tax on $%i at the Encinitas store is: $%.2f\n", fDollarAmount, fSalesTaxEncini tas);
    printf("\nThe sales tax on $%i at the La Jolla store is: $%.2f\n", fDollarAmount, fSalesTaxLaJoll a);

    }
  • Meetee
    Recognized Expert Contributor
    • Dec 2006
    • 928

    #2
    Originally posted by phxgirl24
    Can anyone tell me why this won't compile?


    #include <stdio.h>
    #include <ctype.h>

    void main ()
    {

    /* Variables defined with corresponding tax rates. */
    float fTaxRateDelMar = .0725;
    float fTaxRateEncinit as = .075;
    float fTaxRateLaJolla = .0775;

    /* Variable defined for user inputed dollar amount to be taxed.*/
    float fDollarAmount = 0.0;
    printf("\nWelco me to Kudler Fine Foods.\n");
    printf("\nPleas e enter the subtotal to be taxed: ");
    scanf ("%f", &fDollarAmount) ;


    /* Check validity of user input (number) - return if input is invalid, continue if input is valid */
    int i = isdigit(fDollar Amount);
    while i==0
    {
    printf("\nPleas e enter a valid number: ");
    scanf ("%f", &fDollarAmount) ;
    int i = isdigit(fDollar Amount);
    }

    /* Calculation variables defined and calculations accomplished. */
    float fSalesTaxDelMar = fDollarAmount * fTaxRateDelMar;
    float fSalesTaxEncini tas = fDollarAmount * fTaxRateEncinit as;
    float fSalesTaxLaJoll a = fDollarAmount * fTaxRateLaJolla ;
    float fTotalSaleDelMa r = fDollarAmount + fSalesTaxDelMar ;
    float fTotalSaleEncin itas = fDollarAmount + fSalesTaxEncini tas;
    float fTotalSaleLaJol la = fDollarAmount + fSalesTaxLaJoll a;

    /* Print statements to display the Sales Tax and Total Sale values. */
    printf("\nThe sales tax on $%i at the Del Mar store is: $%.2f\n", fDollarAmount, fSalesTaxDelMar );
    printf("\nThe sales tax on $%i at the Encinitas store is: $%.2f\n", fDollarAmount, fSalesTaxEncini tas);
    printf("\nThe sales tax on $%i at the La Jolla store is: $%.2f\n", fDollarAmount, fSalesTaxLaJoll a);

    }
    After compiling you program, I found some errors, which I want you to correct.
    Kindly change void main() to int main() and return 0; at the end of main function.
    Also change while i==0 to while (i==0). This is a syntax error.

    I am not aware of your program functionality. So I got output as
    Welcome to Kudler Fine Foods.

    Please enter the subtotal to be taxed:

    So do the changes and ask if any problem.

    Regards

    Comment

    • phxgirl24
      New Member
      • Aug 2007
      • 4

      #3
      Originally posted by zodilla58
      After compiling you program, I found some errors, which I want you to correct.
      Kindly change void main() to int main() and return 0; at the end of main function.
      Also change while i==0 to while (i==0). This is a syntax error.

      I am not aware of your program functionality. So I got output as
      Welcome to Kudler Fine Foods.

      Please enter the subtotal to be taxed:

      So do the changes and ask if any problem.

      Regards

      I made the changes you suggested but I'm still getting the same parce error:

      line 45: Parse Error, expecting `'}''
      'int i = isdigit(fDollar Amount)'

      Any idea what's causing it?

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by zodilla58
        .Kindly change void main() to int main() and return 0; at the end of main function.
        Can we have this engraved on titanium plaques and nail them to the front door
        of every possible C/C++ forum please?

        kind regards,

        Jos

        Comment

        • Meetee
          Recognized Expert Contributor
          • Dec 2006
          • 928

          #5
          Originally posted by phxgirl24
          I made the changes you suggested but I'm still getting the same parce error:

          line 45: Parse Error, expecting `'}''
          'int i = isdigit(fDollar Amount)'

          Any idea what's causing it?
          I think you have forgot to put "}" somewhere near 'int i = isdigit(fDollar Amount)' line. Kindly check that. You will have to check all "{" have it's "}".

          Comment

          • Meetee
            Recognized Expert Contributor
            • Dec 2006
            • 928

            #6
            Originally posted by JosAH
            Can we have this engraved on titanium plaques and nail them to the front door
            of every possible C/C++ forum please?

            kind regards,

            Jos
            Have I done anything wrong? Actually it was causing error. Kindly correct me if I am wrong.

            Regards

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by zodilla58
              Have I done anything wrong? Actually it was causing error. Kindly correct me if I am wrong.

              Regards
              You haven't done anything wrong at all; as a matter of fact your statement is
              1000% correct as per the definitiion in the Standard; I'd wish more people used
              a proper int main() instead of that silly Microsoftism 'void main()'.

              Hence the engraved plaques ;-)

              kind regards,

              Jos

              Comment

              • Meetee
                Recognized Expert Contributor
                • Dec 2006
                • 928

                #8
                Originally posted by JosAH
                You haven't done anything wrong at all; as a matter of fact your statement is
                1000% correct as per the definitiion in the Standard; I'd wish more people used
                a proper int main() instead of that silly Microsoftism 'void main()'.

                Hence the engraved plaques ;-)

                kind regards,

                Jos
                I see. I think your suggestion of plaques is not a bad idea..! lol

                Regards

                Comment

                • phxgirl24
                  New Member
                  • Aug 2007
                  • 4

                  #9
                  Originally posted by zodilla58
                  I think you have forgot to put "}" somewhere near 'int i = isdigit(fDollar Amount)' line. Kindly check that. You will have to check all "{" have it's "}".

                  I have checked them and that's what's driving me nuts. There are only 2 sets of "{ }" in the code - one set for the main function and one for the while loop and both complete sets are there.

                  Comment

                  • JosAH
                    Recognized Expert MVP
                    • Mar 2007
                    • 11453

                    #10
                    Originally posted by phxgirl24
                    I have checked them and that's what's driving me nuts. There are only 2 sets of "{ }" in the code - one set for the main function and one for the while loop and both complete sets are there.
                    Care to post you code again? Because except for the "i == 0" instead of "(i == 0)"
                    there were no syntax errors in your code. You're on the wrong track or your code
                    is not what we see here.

                    kind regards,

                    Jos

                    ps. and put [ code ] before your code and [ /code ] afterwards (without the spaces).

                    Comment

                    • weaknessforcats
                      Recognized Expert Expert
                      • Mar 2007
                      • 9214

                      #11
                      This is C.

                      In C all variables must be defined at the start of the function.

                      Only in C++ can you define variables in the middle of the code.

                      Comment

                      • phxgirl24
                        New Member
                        • Aug 2007
                        • 4

                        #12
                        Originally posted by weaknessforcats
                        This is C.

                        In C all variables must be defined at the start of the function.

                        Only in C++ can you define variables in the middle of the code.

                        That was the problem, thanks.

                        Now that I got that working, anybody have any idea how I can validate that the user is entering a number and not a letter or special character?

                        Comment

                        • weaknessforcats
                          Recognized Expert Expert
                          • Mar 2007
                          • 9214

                          #13
                          Originally posted by phxgirl24
                          Now that I got that working, anybody have any idea how I can validate that the user is entering a number and not a letter or special character?
                          Yes. Start a new thread. When I see it I will respond.

                          Comment

                          Working...