按降序计算双精度
Cout Doubles in Descending Order C++
我需要帮助。我正在编写这个程序,需要计算。csv文件中两个int之间的差异。找到差异很容易,但当我计算差异列表时,它们没有特定的顺序。我想挑出最大的差值,并具体计算出来。我该怎么做呢?
double diff;
int astate;
string line8;
ifstream myfile8 ("elect12.csv");
//cout << endl << "Total Popular Votes for Other Candidates: ";
while (getline (myfile8, line))
{
istringstream iss(line);
int a, b, c, d, e;
if (!(iss >> a >> b >> c >> d >> e )) //{ break; }
diff = (a-b);
diff = diff/d;
diff = diff*100;
astate = diff;
/*cout << "Obama's best state was " << line8 << ", where he won by " << diff << " points." << endl;*/
cout << astate << endl;
差异被转换成百分比。现在,a &B正在被退回。我如何只返回最大的差异?
如果这没有意义,我很抱歉。
将当前差值与之前的最大差值(存储在初始化的变量astate
中)进行比较,如果比之前的最大差值大,则赋值。在循环结束后打印astate
的值
相关文章:
- Fmod 函数清楚地输出一个预期的双精度值,但 if(fmod == 预期的双精度值)的计算结果不是 true
- 为什么 2 个双精度值之间的差值计算错误?
- 如何使用 2 个迭代器进行求和函数计算映射<字符串、双精度>
- 通过更改代码格式来计算结构向量中包含的双精度变量的平均值的不同结果?
- C++ [链接器错误] 未定义对"执行计算(字符,双精度)"的引用
- 小数点后的数字,用于双精度变量/C++计算
- 如何计算双精度/浮点C++中的位数
- 涉及双精度数的计算
- c++ 如何计算涉及双精度数据类型模数的数学表达式
- 用C++计算小双精度数时出错
- 为什么我所有的双精度计算都在循环中给出相同的结果
- 用双精度计算 pow 会给出错误的结果
- c++ linux x86_64中如何控制双精度计算以避免舍入误差
- 在不切割变量的情况下计算双精度
- 在计算双精度值期间,错误计数增加
- 计算双精度数组中所有元素的和
- 按降序计算双精度
- 使用EXPECT_EQ计算双精度或浮点数的和时出错
- 浮点计算给出的结果与使用双精度计算的结果不同
- C++计算比双精度或长双精度更精确