gpt4 book ai didi

c++ - 答案在不应该的时候四舍五入 C++

转载 作者:行者123 更新时间:2023-11-28 01:53:41 25 4
gpt4 key购买 nike

<分区>

#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
using namespace std;

int main()
{
//Declaration of Variables
float TotalCollected; // Total Amount Collected from sales
double sales; // Sale excluding tax
float CountyTaxRate; // Tax rate for County
float StatesTaxRate; // Tax rate for state

cout << setprecision(2) << fixed << showpoint;

//We get data from the user
cout << "What is the Total Collected Amount? ";
cin >> TotalCollected;
cout << "What is the County Tax rate? ";
cin >> CountyTaxRate;
cout << "What is the State Tax rate ";
cin >> StatesTaxRate;

//Calculations
sales = TotalCollected / (1 + StatesTaxRate + CountyTaxRate);

//Output
cout << "Sales: $" << sales << endl;
return 0;
}

县税率= .02 州税率= .04
总收集量= 26572.89

输出应该是 25068.76,但我一直得到 25068.77。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com