gpt4 book ai didi

c++ - 我的 C++ 计算器似乎出了什么问题?

转载 作者:搜寻专家 更新时间:2023-10-31 02:01:53 25 4
gpt4 key购买 nike

<分区>

#include <iostream>

using namespace std;

int main()
{
int num1,num2,answer;
char choice = 'Y',input;

while (choice == 'Y' || choice == 'y')
{
cout << "Enter the first number: " << endl;
cin >> num1;
cout << "Enter the second number: " << endl;
cin >> num2;

cout << "What operation would you like to use?" << endl << endl;
cout << "Press [A] if you want to use Addition." << endl;
cout << "Press [S] if you want to use Subtraction." << endl;
cout << "Press [M] if you want to use Multiplication." << endl;
cout << "Press [D] if you want to use Division." << endl;

switch(input)
{
case 'A':
case 'a':
{
answer=num1+num2;
cout << "This is the sum of your equation: " << answer << endl;
break;
}
case 'S':
case 's':
{
answer=num1-num2;
cout << "This is the difference of your equation: " << answer << endl;
break;
}
case 'M':
case 'm':
{
answer=num1*num2;
cout << "This is the product of your equation: " << answer << endl;
break;
}
case 'D':
case 'd':
{
answer=num1/num2;
cout << "This is the quotient of your equation: " << answer << endl;
break;
}
default:
{
cout << "Invalid Operation..." << endl;
break;
}
}
cout << "Do you want to go again? (Y/N) " << endl;
cin >> choice;
}

cout << "See you later." << endl;

return 0;
}

所以我大约一个半月前才开始上大学,我想我应该尝试一下还没有教给我们的代码。但是我遇到了一个问题,每当我构建我的程序时它都没有显示错误。但它并没有按照我的预期去做,成为一个计算器。它立即跳到,“你想再去一次吗?”输入 2 个数字后,它甚至不会让用户选择操作,更不用说计算了。我的代码似乎有什么问题?

[编辑]我忘了把 cin >> input;在询问要使用哪个操作之后。

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