-2
如果有人有一些建議 - 我可以利用幫助。該程序編譯,但沒有
正確計算。我曾經嘗試了很多次的嘗試,並且對此感到焦慮。有什麼建議麼?
我必須初始化所有這些變量?謝謝....C++計算器程序。問題
//This program mimics a calculator
//*****************************************
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double firstint, secint, ansrlt, ansrlt2, ansrlt3, ansrlt4;
char operat;
cout << fixed << showpoint;
cout << setprecision(4);
cout << "This program mimics a standard calculator and outputs a result accurate to 4 decimal
places." <<endl;
cout << '\n';
cout << "Please enter 1st Integer to be calculated: ";
cin >> firstint;
cout << '\n';
cout << "Please enter operation to be performed in the form of *, /, +, - : ";
cin >> operat;
cout << '\n';
cout << "Please enter 2nd Integer to be calculated: ";
cin >> secint;
cout << '\n';
if (operat == '/' && secint == 0)
cout << "Division by 0 not allowed enter again." << endl;
cin.get();
if (operat == '*')
ansrlt = firstint * secint;
cout << firstint << " " << operat << " " << secint << " = " << ansrlt << endl;
cin.get();
if (operat == '/')
ansrlt2 = firstint/secint;
cout << firstint << " " << operat << " " << secint << " = " << ansrlt2 << endl;
cin.get();
if (operat == '+')
ansrlt3 = firstint + secint;
cout << firstint << " " << operat << " " << secint << " = " << ansrlt3 << endl;
cin.get();
ansrlt4 = firstint - secint;
cout << firstint << " " << operat << " " << secint << " = " << ansrlt4 << endl;
cin.get();
return 0;
}
功課吧?殺手。它以什麼方式不能正確計算? – 2014-09-23 19:20:25
Stackoverflow不是一個在線調試器... – Borgleader 2014-09-23 19:20:58
我做了調試和編譯,沒有被拾取。答案只是每次輸出相同。所以例如2 + 2 = 4; 2 * 2 = 4; 2-2 = 4; 2/2 = 4。我現在將進行修改。另外{}也不是文本格式。我根據文本構建它。 – Chris 2014-09-23 19:32:54