該值從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