gpt4 book ai didi

c - C 程序的错误和警告

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

第 41 行出现错误:“int”之前有预期表达式 第 45 行:建议在 '&' 操作数的比较周围使用括号

我还想确定 43-45 中的代码是否有意义。

我是第一次在这个论坛上发帖,我是 C 新手,所以请容忍这篇文章的业余性质

#include<stdio.h>
#include<math.h>
int main(void)

{
// LOCAL DECLARATIONS

int bricks; //the number of bricks available
int spheres; //the number of spheres available
int prisms; //the number of prisms available
int final_string(int bricks, int spheres, int prisms); //the longest possible string with the given shapes in an alternating fashion

// EXECUTABLE STATEMENTS

printf("\nEnter the number of bricks: ");
scanf("%d", &bricks);
printf("Enter the number of spheres: ");
scanf("%d", &spheres);
printf("Enter the number of prisms: ");
scanf("%d", &prisms);
printf("\nLongest possible string of alternating shapes usuing only two different shapes: %d", int final_string(int bricks, int spheres, int prisms));

int final_string(int bricks,int spheres,int prisms);
{
return bricks * (bricks > spheres & bricks > prisms) + spheres * (spheres > bricks & spheres > prisms) + prisms * (prisms > bricks & prisms > spheres);
}

return(0);

最佳答案

  1. 从该行中删除所有 int:

    printf("\nLongest possible string of alternating shapes usuing only two different shapes: %d", int final_string(int bricks, int spheres, int prisms));
  2. 删除final_string定义中函数签名后面的分号

  3. final_string 移至 main 之外
  4. 使用逻辑&&运算符而不是按位&
  5. 购买并阅读 a C book
  6. 以后在 http://codereview.stackexchange.com 上提出这样的“问题”

关于c - C 程序的错误和警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17280636/

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