Salve sto scrivendo un codice in cui devo riempire un array di numeri double,il problema sta che il rand mi genera sempre 0 oppure il numero -842150451.
C++:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
double* generatore(int n[],int totale);
void stampa(int n[],int totale);
int main()
{
int* numeri;
int totale;
cout << "quanti numeri vuoi generare? ";
cin >> totale;
numeri = new int[totale];
generatore(numeri,totale);
stampa(numeri,totale);
return 0;
}
double* generatore(int n[],int totale)
{
srand(time(NULL));
double* array=new double[totale];
for (int j = 0; j < totale;j++)
{
double f = (double)rand() / 100.0;
array[j] = f;
}
return array;
}
void stampa(int n[],int totale)
{
for (int j = 0; j < totale;j++)
{
cout << n[j] << endl;
}
}