我正在努力学习编程。这是一个简单的问题,但我无法解决。 为什么我收到错误?怎么了? 我怎么解决这个问题?请帮助我。
这是问题定义和我的代码:
#include<stdio.h>
void calculateCharged(int c) {
int a;
int hours = scanf("%d", &a);
int totalFee = 25;
}
int main(void) {
int i;
int b;
printf("Please Enter Number of Cars ");
scanf("%d", &i);
for (b = 0; b < i; b++) {
calculateCharged(hours)
if (hours)<8
totalFee += hours * 0, 5
else if hours < 24
int additionalHours = hours - 7
totalFee += additionalHours * 5
totalFee += hours * 0, 5
else
int days = hours / 24
int extraHours = hours % 24
totalFee += days * 50
totalFee += days * 24 * 0, 5
totalFee += extraHours * 5
totalFee += extraHours * 0, 5
}
}
最佳答案
解决方案实际上就在错误消息中。
在 C 语言中,if
的语法需要将条件括在括号内。
应该是这样
else if(hours < 24)
这是一个很好的暗示,表明您的第一个 if
已被接受。
此外,您的范围还需要大括号,您的代码看起来像未缩进的 Python 或其他东西。在尝试使用新的编程语言之前,请阅读一些基本引用资料。
关于c - [错误]:expected '(' before 'hours' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42668384/