Thread: Syntax errors

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    1

    Syntax errors

    Hello Members,

    I got an error with a recent tax coding project I've been doing. I've run this code before and it ran perfectly but I'm not sure if I misedited a variable or something when I try it I get three errors.

    G:\payroll.c In function `main':



    On line 21 this is the error -G:\payroll.c syntax error before "else"

    This is the code on line 27- else{



    On line 48 this is the error -G:\payroll.c syntax error at end of input

    This is the code on line 48- return;




    This is entire coding from my work

    //************************************************** ***************************************
    //
    //
    //************************************************** ******************
    #include <stdio.h>
    #include <stdlib.h>
    #define pause system("pause");

    main() {
    //
    float hourlyRate, hoursWorked, grossPay;
    float regPay, otPay;
    if(hoursWorked> 40){
    regPay=hourlyRate * 40;
    otPay= (hoursWorked - 40) * 1.5* hourlyRate ;



    //End if

    else{
    regPay=hourlyrate* hoursWorked;
    otPay= 0;



    printf("Please enter Your Hourly Rate: ");
    scanf("%f", &hourlyRate) ;
    printf("Please enter number of hours worked: ");
    scanf("%f", &hoursWorked);
    grossPay= regPay+otPay ;
    printf("====================\n");
    printf("Hourly Rate: $%.2f \n",hourlyRate);
    printf("Hourly Work: %.1f\n",hoursWorked);
    printf("Gross Pay: $%.2f \n");
    printf("====================\n");



    printf("Gross Pay: $%.2f \n",grossPay);
    printf("Gross Pay: $%.2f \n",otPay);
    printf("Gross Pay: $%.2f \n",regPay);




    pause;
    return;


    // End of Main





    Can anyone help me?

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    You're missing the closing brace before the "else" (to close off the "if" part).

    Next time, remember to use code tags for your code to maintain the spacing, like this:

    [code]
    Your code here.
    [/code]
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    You need to get data into your variables first and then make calculations based on those values. It doesn't work the way you are trying. There is no magical connection between your input of hoursWorked and hourlyRate such that regPay and otPay will suddenly have correct data. As it stands now you are operating on uninitialized values and any compiler worth a damn should be spitting out warnings about that code.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. syntax errors
    By aromash in forum C++ Programming
    Replies: 8
    Last Post: 09-14-2011, 06:53 AM
  2. syntax errors
    By newguyps in forum C++ Programming
    Replies: 5
    Last Post: 07-29-2011, 10:25 AM
  3. why i get 2 syntax errors here .
    By transgalactic2 in forum C Programming
    Replies: 2
    Last Post: 11-30-2008, 03:18 PM
  4. HELP!! Syntax errors
    By theused96 in forum C Programming
    Replies: 2
    Last Post: 09-20-2007, 04:29 PM
  5. syntax errors
    By nesagsar in forum C++ Programming
    Replies: 33
    Last Post: 12-14-2006, 02:03 PM