将C+中的两个浮点数相乘+;给我非数字结果 我是C++新手,我的第一个程序有问题。我试着乘以两个浮点数,结果总是像1.1111e+1,其中1s是随机数。下面是我写的小程序 #include <iostream> #include <string> #include <conio.h> using namespace std; int main() { float bank; float dollor; cout<<"Enter amount of $ deposited at Bank: ";//the data to input is 5000 cin>>bank; cout<<"Enter current $ price: ";//1usd = 800mmk: the data to input is 800 cin>>dollor; bank*=dollor;//all deposited $ to local currency cout<<"Result is "<<bank; getch(); } #包括 #包括 #包括 使用名称空间std; int main() { 浮动银行; 浮托; 库特班克; 库多洛; 银行*=美元;//将所有美元存入当地货币 cout

将C+中的两个浮点数相乘+;给我非数字结果 我是C++新手,我的第一个程序有问题。我试着乘以两个浮点数,结果总是像1.1111e+1,其中1s是随机数。下面是我写的小程序 #include <iostream> #include <string> #include <conio.h> using namespace std; int main() { float bank; float dollor; cout<<"Enter amount of $ deposited at Bank: ";//the data to input is 5000 cin>>bank; cout<<"Enter current $ price: ";//1usd = 800mmk: the data to input is 800 cin>>dollor; bank*=dollor;//all deposited $ to local currency cout<<"Result is "<<bank; getch(); } #包括 #包括 #包括 使用名称空间std; int main() { 浮动银行; 浮托; 库特班克; 库多洛; 银行*=美元;//将所有美元存入当地货币 cout,c++,C++,4e+006是4000000的正确答案,这是5000*800的正确答案 更详细地说,4e+006代表4*10**6,其中10**6是十的六次方 要使用定点表示法,您可以这样更改程序: #include <iomanip> ... cout << "Result is " << fixed << bank; #包括 ... 好吧,5000乘800确实是4e6,也就是4*10^6400000。试试: #include <iomanip>

4e+006
4000000
的正确答案,这是
5000*800
的正确答案

更详细地说,
4e+006
代表
4*10**6
,其中
10**6
是十的六次方

要使用定点表示法,您可以这样更改程序:

#include <iomanip>
...
cout << "Result is " << fixed << bank;
#包括
...

好吧,5000乘800确实是4e6,也就是4*10^6400000。

试试:

#include <iomanip>

//...
cout << "Result is "<< setprecision(2) << bank;
#包括
//...

这是科学记数法


看一看。除其他外,它还展示了如何用定点符号打印数字。

-1:对我来说似乎是正确的答案。+1因为我认为这是一个有效的问题,尽管答案是我在中学学到的。
cout.precision(2);
cout << "Result is " << fixed << bank;