gpt4 book ai didi

c - 我在一本使用 Xcode 的教科书中发现运行 C 程序时出错。

转载 作者:行者123 更新时间:2023-11-30 19:32:47 25 4
gpt4 key购买 nike

我实际上按照我用来学习 C 的教科书中的方式编写了这段代码。我不确定这些错误意味着什么或从哪里开始。请帮忙。我正在使用 Xcode。

//  Specific Age Calculator
//
// Created by Christopher Pettit on 10/11/17.
// Copyright © 2017 Christopher Pettit. All rights reserved.

#include <stdio.h>
#define TARGET_AGE 88

int year1, year2;

int calcYear(int year1);


int main(void)
{
// Ask the user for their birth year
printf("What year were you born?\n");
printf("Enter as a 4-digit year (YYYY) " );
scanf(" %d", &year1);

// Calculate the future year and display it
year2 = calcYear(year1);

printf("Since you were born in %d, you will be %d in %d. ",
year1,TARGET_AGE,year2);

return 0;

// This function to get the future year
int calcYear (int year1);

{
return (year1+TARGET_AGE);
}

}

This is the error that Xcode produces

最佳答案

花括号放错了位置。因此,函数 calcYear 未定义,因为它隐藏在 main 中。

在不解释程序含义的情况下,只是为了修复链接器错误,该错误表示没有 calcYear 的定义,代码可能如下所示:

    return 0;
} // this one inserted

// This function to get the future year
int calcYear (int year1) // ; this semicolon was deleted

{
return (year1+TARGET_AGE);
}

//} this one deleted

关于c - 我在一本使用 Xcode 的教科书中发现运行 C 程序时出错。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46697504/

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