0

I need to randomly generate a 8-digit number (from 00000000 to 99999999) so I used an srand() function, but when I run it, happens to be that the max number of digits is five (ex. 31567). I changed 'int' with 'double' in order to get the 8 digits, but an error message (

invalid operands of types 'int' and 'double' to binary'operator%'

) appears. Looking forward a code that could help me use double variables, found out some examples, the problem is that when I try to run 'em, my compiler (Dev C++ 5.7.1) sends a c++0x_warning.h (

This file requires compiler and library support for the \ISO C++ 2011 standard. This support is currently experimental, and must be \enabled with the -std=c++11 or -std=gnu++11 compiler options.

). I don't know what to do at this point.

This is the code I've been using (the one which prints only 5 digits):

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<cstdlib>
#include<time.h>
#include<iostream>
#include<locale.h>
int main(int argc, char *argv[])
{
    setlocale(LC_ALL, "");
    using namespace std;
    int num=0, cant=1, cont=0, bot=00000000, top=99999999;
    /*Aquí se incluyen todas las variables que se utilizarán en la función random para generar un folio.*/
        srand(time(NULL));
        while(cont<cant)
        /*Generará una cantidad de ocho dígitos aleatoriamente que servirá como folio.*/
        {
            num=bot+rand()%((top+1)-bot);
            /*La cantidad irá desde el 00000000 hasta el 99999999 de manera aleatoria*/
            cout<<"\n\n Utilice el folio que se muestra a continuación para recoger su orden: "<<num;
            cont++;
        }
    getch();
    return 0;
}
Rixiha
  • 1
  • 1
  • there's no `double` in your code – phuclv Jun 01 '21 at 15:19
  • 4
    Read about [RAND_MAX](https://en.cppreference.com/w/cpp/numeric/random/RAND_MAX). You might have to combine multiple values to get that large a range. – Pete Becker Jun 01 '21 at 15:20
  • Instead of `double`s, can you use `long long`'s? I don't know what exactly the standard says about the length of a `long long`, but might be worth a try – mattlangford Jun 01 '21 at 15:24
  • See [this](https://en.cppreference.com/w/cpp/numeric/random/uniform_int_distribution) for how you should be generatig random integers in C++ now. – NathanOliver Jun 01 '21 at 15:26
  • 4
    If your compiler tells you that support of C++11 is experimental, it is *ancient*. Like, at least 10 years old. Can you update it to something newer? You don't need to update Dev-C++, you only need to update compiler it is using (MinGW likely). – Yksisarvinen Jun 01 '21 at 15:28
  • @phuclv There's no 'double' instead of 'int' because it appears as an error. – Rixiha Jun 02 '21 at 16:35
  • @NathanOliver Thanks, I'll check it. – Rixiha Jun 02 '21 at 16:39
  • @Yksisarvinen Well, I guess I'll have to do that. – Rixiha Jun 02 '21 at 16:41

0 Answers0