我正在尝试用 C++ 制作一个小型计算器但它只计算科学计数法
我是 C++ 新手,首先我正在制作一个乘法计算器。问题是每当我计算超过 1000 的数字时,它只会计算科学计数法。代码如下,有人可以帮忙吗?
#include <iostream>
using namespace std;
int main()
{
float value;
cout << "Please enter value ";
cin >> value;
float multBy;
cout << "\nWhat would you like to multiply by? ";
cin >> multBy;
float answer = value * multBy;
cout << "\nYour answer is " << answer;
system("pause>0");
}
I'm new to C++ and to start off I'm making a multiplication calculator. The problem is whenever I do numbers over ~1000 it just calculates scientific notations. The code is below, can anyone help?
#include <iostream>
using namespace std;
int main()
{
float value;
cout << "Please enter value ";
cin >> value;
float multBy;
cout << "\nWhat would you like to multiply by? ";
cin >> multBy;
float answer = value * multBy;
cout << "\nYour answer is " << answer;
system("pause>0");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是您修改后的代码。通过使用showpoint和fixed,结果以定点表示法显示,通过使用“set precision”我们可以调整结果中小数点后的数字。
The following is modified code of yours. By the use of showpoint and fixed , the results are displayed in fixed point notation and by the use of "setprecision" we can adjust the numbers after decimal in result.