mardi 1 juin 2021

Generating a 8 digit random number in Dev C++ [duplicate]

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;
}



Aucun commentaire:

Enregistrer un commentaire