gpt4 book ai didi

c - 需要帮助修复代码以便可以编译

转载 作者:行者123 更新时间:2023-11-30 20:05:11 26 4
gpt4 key购买 nike

作为作业的一部分,我必须用 C 语言编写一段代码,以在开始时间和持续时间相加时给出结束时间。

例如,“开始时间为 1245。持续时间为 345。结束时间为 1630”

这是我的代码:

#include <stdio.h>

void addTime(int start, int duration);
int main()

{
addTime(1045, 345);
addTime(800, 435);
addTime(2300, 300);
}

void addTime(int start, int duration)

if(start + duration > 2400)
{
printf("Start time is %d. Duration is %d. End time is %d\n", start, duration, (((((60*(start/100))+(((start/100)%)*100)) + ((60*(duration/100))+(((duration/100)%)*100)))/60) + (((((((60*(start/100))+(((start/100)%)*100)) + ((60*(duration/100))+(((duration/100)%)*100))/60)%)/3600)%))));
}

else
{
printf("Start time %d. Duration is %d. End time is %d\n", start, duration, (((((60*(start/100))+(((start/100)%)*100)) + ((60*(duration/100))+(((duration/100)%)*100)))/60) + (((((60*(start/100))+(((start/100)%)*100)) + ((60*(duration/100))+(((duration/100)%)*100)))/60)%));
}

这是错误消息:

task3.c: In function ‘addTime’:
task3.c:14:1: error: expected declaration specifiers before ‘if’
if(start + duration > 2400)
task3.c:19:1: error: expected declaration specifiers before ‘else’
else
task3.c:22:1: error: expected ‘{’ at end of input

最佳答案

您缺少 addTime 实现周围的大括号 ({}):

void addTime(int start, int duration) 
{ /* here */
if(start + duration > 2400)
{
printf("Start time is %d. Duration is %d. End time is %d\n", start, duration, (((((60*(start/100))+(((start/100)%)*100)) + ((60*(duration/100))+(((duration/100)%)*100)))/60) + (((((((60*(start/100))+(((start/100)%)*100)) + ((60*(duration/100))+(((duration/100)%)*100))/60)%)/3600)%))));
}
else
{
printf("Start time %d. Duration is %d. End time is %d\n", start, duration, (((((60*(start/100))+(((start/100)%)*100)) + ((60*(duration/100))+(((duration/100)%)*100)))/60) + (((((60*(start/100))+(((start/100)%)*100)) + ((60*(duration/100))+(((duration/100)%)*100)))/60)%));
}
} /* and here */

关于c - 需要帮助修复代码以便可以编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33056021/

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