gpt4 book ai didi

c - 如何让 C 程序回复一封信并吐出其他内容?

转载 作者:太空宇宙 更新时间:2023-11-04 01:43:08 25 4
gpt4 key购买 nike

我似乎无法编译这个程序。

我不断收到错误:

'Ammonia' undeclared 'Carbon_Monoxide' undeclared

等等。我是否使用了正确的开关功能?

/*This program will report the content of a compressed-gas cylinder based on the first letter of the cylinder's color.*/


#include <stdio.h>
int main (void)
{
int x;
char o, b, y, g;
int pause;

o = Ammonia;
b = Carbon_Monoxide;
y = Hydrogen;
g = Oxygen;

printf(" Enter a character representing the observed color of the cylinder \n" );
scanf("%d", &x);
switch (x)
{

case 'o': printf("The content is Ammonia\n");
case 'b': printf("The content is Carbon Monoxide\n");
case 'y': printf("The content is Hydrogen\n");
case 'g': printf("The content is Oxygen\n");
default: printf("Character out of range \n");
}

printf("After Switch \n");
printf("Enter new character to continue \n");
scanf("%d", &pause);

return 0;
}

最佳答案

它与您的 switch 语句无关,但您可能不得不对这四行的含义感到困惑:

 o = Ammonia;
b = Carbon_Monoxide;
y = Hydrogen;
g = Oxygen;

您没有在任何地方使用如此定义的变量,并且 undefined symbol “Ammonia”、“Carbon_Monoxide”等 - 这是您看到的错误的原因。

关于c - 如何让 C 程序回复一封信并吐出其他内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1496009/

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