Q:

Why do I get floating point error while generating a random number using G++?

I am using the G++ Compiler. The following code is getting compiled correctly.
#include<iostream>
#include<cstdlib>
#include<stdio.h>

using namespace std;

int random(int max)
    {
    return rand() / (RAND_MAX / max + 1);
    }

int main()
  {
    for(int iteration=0; i<10; i++)
    {
    int myNum=random(130);
    myNum=myNum-(myNum%iteration); /* This line causes exception. */
    (myNum<0)?(myNum=myNum*-1):myNum;
    cout<<"\nRandom number is "<<myNum<<"\n";
    }
  }

During runtime, it is generating the following exception..

g++ Implement.cc
./a.out
Floating point exception

Could you please help me to rectify this error?

A:

You are taking % against 0
for(int iteration=0; i<10; i++)
                  ^^^

