Dev C++中for循环(C语言)出错
Error in for loop (C language) in Dev C++
我在 运行 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);
}
}
我收到以下错误
[Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
在 for
循环的第一部分中声明变量是作为 C99 标准的一部分添加到 C 中的一项功能。但是,大多数编译器默认使用不支持此构造的旧 C89 标准。
您需要将 i
的声明移到 for
循环之外:
int i;
for(i=0;i<=10;i++)
{
...
我在 运行 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);
}
}
我收到以下错误
[Error] 'for' loop initial declarations are only allowed in C99 or C11 mode
在 for
循环的第一部分中声明变量是作为 C99 标准的一部分添加到 C 中的一项功能。但是,大多数编译器默认使用不支持此构造的旧 C89 标准。
您需要将 i
的声明移到 for
循环之外:
int i;
for(i=0;i<=10;i++)
{
...