C++计算器程序.问题
C++ Calculator Prog. Issue
如果有人有什么建议,我可以利用帮助。程序编译,但不编译
正确计算。我已经尝试了无数次重述,但我陷入了困境。有什么建议吗
我必须初始化所有这些变量?非常感谢。
//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;
}
首先,你应该解释你做了什么,发生了什么,以及你期望发生什么,因为这通常会让事情变得更容易任何读到你问题的人。
然而,你的if的身体周围到处都是你失踪的{}。
例如,它应该是
if (operat == '*') {
ansrlt = firstint * secint;
cout << firstint << " " << operat << " " << secint << " = " << ansrlt << endl;
}
(并且去掉cin.get()
调用,除非您将它们用于调试目的)
相关文章:
- 基于boost的程序的静态链接——zlib问题
- 使用mongocxx驱动程序时包含头文件问题
- 运行程序时出现问题
- C++问题:用户认为数字1-100,程序提出问题不超过6次即可得到答案。无法正确
- 将应用程序从32位移植到64位时出现问题
- 我试图制作一个程序,要求用户输入问题和答案,但程序循环不正确
- C++ 每次运行程序时我都会"nan"输出的问题
- 这是使用回溯的 nqueen 问题,但我使用了动态 2d 数组,我的程序编译良好,但不返回任何输出
- 最大的回文产品 - 程序未运行,编写解决方案但无法理解问题
- 如何解决在负数的情况下程序以相同方式工作的问题?
- 在树莓派上用libtorch构建程序时的链接问题
- 覆盖应用程序的低级别键盘挂钩问题
- 运行长度编码程序 c++ 的问题
- 编译 Cilk Plus 程序时遇到问题
- 我的堆栈和库存清单程序的结构有什么问题?
- 系统错误:程序无法启动,因为您的计算机中缺少MSVCP140D.DLL。尝试重新安装该程序以解决此问题
- wxWidgets 拖放文件事件处理程序初始化问题(无效static_cast)
- 桌面计算器出现问题.C++程序设计语言
- 内存泄漏问题c++程序
- 写函数的基本问题.程序随机跳到最后