我正在尝试学习编程。这是一个简单的问题,但我无法解决。
为什么会出现错误?怎么了?
我怎么解决这个问题?请帮我。
这是问题定义和我的代码:
#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
}
}
最佳答案
我没有阅读您的问题定义,但是您的代码至少应该像这样在语法和逻辑上是正确的:
#include<stdio.h>
float totalFee = 0;
int hours = 0;
int main(void) {
int i;
int b;
printf("Please Enter Number of Cars ");
scanf("%d", &i);
for (b = 0; b < i; b++) {
scanf("%d", &hours);
if (hours < 8) {
totalFee += hours * 0.5;
} else if (hours < 24) {
float additionalHours = hours - 7;
totalFee += additionalHours * 5;
totalFee += hours * 0.5;
} else {
float days = hours / 24;
float extraHours = hours % 24;
totalFee += days * 50;
totalFee += days * 24 * 0.5;
totalFee += extraHours * 5;
totalFee += extraHours * 0.5;
}
}
}
关于c - [错误] :expected '(' before 'hours' ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42668384/