我正在尝试用 C++ 制作一个小型计算器但它只计算科学计数法

发布于 2025-01-10 01:09:19 字数 466 浏览 2 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雅心素梦 2025-01-17 01:09:19

以下是您修改后的代码。通过使用showpoint和fixed,结果以定点表示法显示,通过使用“set precision”我们可以调整结果中小数点后的数字。

#include<iostream>
#include<iomanip>
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 " <<showpoint<<fixed<<setprecision(2)<<answer;
    system("pause>0");
}

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.

#include<iostream>
#include<iomanip>
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 " <<showpoint<<fixed<<setprecision(2)<<answer;
    system("pause>0");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文