c - [错误]:expected '(' before 'hours'

标签 c if-statement compiler-errors runtime-error

我正在努力学习编程。这是一个简单的问题,但我无法解决。 为什么我收到错误?怎么了? 我怎么解决这个问题?请帮助我。

这是问题定义和我的代码:

enter image description here

#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/

相关文章:

java - 如何使用具体参数进行子类化

c - 用MSVC判断一段代码是否退出程序

c - 什么时候必须使用 malloc 分配内存?

html - 如何用c语言通过tcp发送http协议(protocol)的html文件?

if-statement - 解决Tableau中IF结果的汇总和非汇总混合错误

compiler-errors - 更新到版本 9 后出现 Angular 编译器错误

c - 术语 "libc"等同于 "C standard library"吗?

java - Java 变量如何与其自身不同?

c - 如何在 C 中绘制一个给定宽度和高度的空矩形?

具有自定义类型和比较器的 C++ 优先级队列不起作用