-
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?
-
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]
-
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.