gpt4 book ai didi

c++ - 为什么这段代码不能运行? [初学者]

转载 作者:太空宇宙 更新时间:2023-11-04 14:44:28 24 4
gpt4 key购买 nike

<分区>

我昨天刚刚学习了“Jumping into C++”,并决定自己去冒险。熟悉“if”语句哦,很久以前使用 Java,我这样做是为了好玩:

#include <iostream>

using namespace std;

int main()
{
int first;
int second;
int choice;
int final;
cout << "Enter your first number:" <<;
endl;
cin >> first >> ;
cout << "Enter your second number:" <<;
endl;
cin >> second >> ;
cout << "Would you like to 1. Add 2. Subtract 3. Multiply 4. Or divide these numbers?" << endl;
if (choice = 1){
final = first + second;
cout << "Your answer is: " << final <<;
return 0;
}
if (choice = 2){
final = first - second;
cout << "Your answer is: " << final <<;
return 0;
}
if (choice = 3){
final = first * second;
cout << "Your answer is: " << final <<;
return 0;

}
if (choice = 4){
final = first / second;
cout << "Your answer is: " << final <<;
return 0;
}
else{
cout << "You probably typed something wrong! Remember, hit your number and hit enter, nothing else!" << endl;
cout << "Ending program." << endl;
return 0;
}

}

为什么这个程序不能正常运行?

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