简体   繁体   English

分数简化算法,浮点异常错误

[英]Fraction simplifying algorithm, floating point exception error

I am a beginner, and i am working on a C++ program that simlifies fractions, however I am getting this weird statement printed, it does not indicate an error, but it gives me the output "Floating point exception: 8". 我是一个初学者,我正在研究一个模拟分数的C ++程序,但是我得到了这个奇怪的语句,但它并不表示错误,但是却给我输出了“浮点异常:8”。

Here is a snippet of my code(not yet complete), I do not ask for code and would prefer if my homework is not done for me, but I welcome logical suggestions to fix or improve the algorithms. 这是我的代码片段(尚未完成),我不要求代码,而是希望我的作业没有完成,但我欢迎有逻辑的建议来修复或改进算法。

void Fraction::simplify()
{
  int i, x = 0, a[100], b[100];
  for (i = 0; i <= den; i++)
  {
    x = num % i;
    if (x == 0)
    {
      b[i] = i;  
    }
  }
}

Thanks a bunch. 谢谢你

x = num % i;

Computes the remaining of dividing num by i 计算划分的剩余num通过i

But i = 0 in the first step, and you cannot devide by zero. 但是在第一步中, i = 0 ,因此您不能将其除以零。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM