0

I'm having problem in running this code in Dev C++.

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

main()
{
    /*
    Write a program to calculate overtime pay of 10 employees.
    Overtime is paid at the rate of Rs. 12.00 per hour for every hour worked above 40 hours. 
    Assume that employees do not work for fractional part of an hour.
    */

    int sal,pay,re;

    for(int i=0;i<=10;i++)
    {
        printf("Write down your over time(in hours):    ");
        scanf("%d",&sal);
        re = sal - 40;
        pay = re * 12;
        printf("Your pay is %d ",pay);
    }

}

I'm receiving the following error

[Error] 'for' loop initial declarations are only allowed in C99 or C11 mode

1

1 Answer 1

4

Declaring a variable in the first part of a for loop was a feature added to C as part of the C99 standard. However, most compilers by default use the old C89 standard that don't support this construct.

You need to move the declaration of i outside of the for loop:

int i;
for(i=0;i<=10;i++)
{
    ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.