0
Follow
0
View

c++ basic problem, there is no help

yy81103892 注册会员
2023-02-25 14:04

Part of the answer refers to GPT, GPT_Pro better solve the problem
A: In
C++, if we use an if else statement to determine that d is a,b, and c and print the name of the value, we can write:

if(d==a)
    cout << "a";
else if(d==b)
    cout << "b";
else if(d==c)
    cout << "c";

Because the C++ language supports switch-case statements, this functionality can be expressed more concisely:

switch(d) {
    case a: 
        cout << "a"; 
        break; 
    case b: 
        cout << "b"; 
        break; 
    case c: 
        cout << "c"; 
        break; 
}  

The code above will do what we want, and it won't make a mistake.
If the answer is helpful, please accept it.

dqyshadowsong 注册会员
2023-02-25 14:04

the reference answer GPT ᴼ ᴾ ᴱ ᴺ ᴬ ᴵ < br / > your code there are several mistakes in grammar and spelling mistakes, I will point out and provide Suggestions. Here's the code you provided, and I've added comments to indicate what needs to be changed:

#include  // 需要添加头文件
using namespace std; // 需要添加分号

int main() { // 缺少左括号
    int a = 0;
    int b = 0;
    int c = 0;
    int d = 0; // 缺少分号

    cout << "请输入小猪a,b,c的重量" << endl;
    cin >> a >> b >> c;
    cout << "a,b,c的质量分别为:" << a << " " << b << " " << c << endl; // 需要添加引号和空格

    d = (a > b ? a : b) > c ? (a > b ? a : b) : c; // 需要添加分号和括号

    cout << "小猪";
    if (d == a) { // 缺少左括号
        cout << "最重的是a" << endl;
    } else if (d == b) { // 缺少左括号
        cout << "最重的是b" << endl;
    } else { // 缺少左括号
        cout << "最重的是c" << endl;
    } // 缺少右括号

    return 0; // 缺少分号和右括号
}


Hopefully, these changes will help you resolve the problem and get your code up and running. If you still have problems, please feel free to ask.

About the Author

Question Info

Publish Time
2023-02-25 14:04
Update Time
2023-02-25 14:04

Related Question

在C#中调用Emgu Cv,读取图片等出现函数不存在是怎么回事?

printf("%c\n",(ch1,ch2))

VS code不识别字母Õ, Ä, Ö, Ü,但编码是UTF-8

如何用眼动仪联动processing做一个创意编程?

如何对模糊搜索到的结果进行click操作

如何存储/缓存请求数据从CMS在Vue3?

getch用法c++

Javascript级联下拉列表

谁来帮帮我c#的文件读写

ecplise连接数据库mysql8.0出错