gpt4 book ai didi

c - Dev C++中for循环(C语言)出错

转载 作者:太空宇宙 更新时间:2023-11-04 06:50:54 29 4
gpt4 key购买 nike

我在 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++)
{
...

关于c - Dev C++中for循环(C语言)出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51523265/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com