该值从0开始,然后可以使用数学的任何操作数进行计算。代码编译成功,但不起作用。终端窗口显示“中止”,“重试”和“取消”。规则是你不能使用2个操作数,只是继续添加前一个数字来表示操作数。在C++中没有2个操作数的数学计算器
#include <iostream>
#include <cmath>
using namespace std;
void Input(double input);
int main()
{
double sign, input;
cout << "This program calculates any given number upto 1 decimal place using the following operators:" << endl;
cout << " '+' - Addition." << endl;
cout << " '-' - Subtraction" << endl;
cout << " '*' - Multiplication." << endl;
cout << " '^' - Root." << endl;
cout << " '/' - Division." << endl;
Input(input);
return 0;
}
void Input(double IN)
{
char q;
char sign;
int Val = 0.0;
cin >> sign >> IN;
while (IN != q)
{
if (sign = '-')
Val -= IN;
if (sign = '+')
Val += IN;
if (sign = '*')
Val *= IN;
if (sign = '/')
Val /= IN;
cout << endl << "Result so far is " << IN;
IN++;
}
}
强烈建议您明确指出是什么给您带来麻烦。我可以在代码中看到一个可能成为问题的重复错误,但我宁愿有固定的门柱。 – user4581301
该程序不起作用,我想根据哪个操作符号提供来计算数字。 – Snehil
它不起作用?什么行/表达?它做什么而不是你想要它做什么? – user4581301