mercredi 30 septembre 2020

How to cast random numbers in an array?

I'm currently trying to create 20 random numbers in an array and set these values to either 0 or 1. The problem I'm having after this is when I try to do a bit of casting to try and get these numbers to doubles. From what I understand (Not much), this should work, but it just outputs 0's and 1's again. I'd really appreciate any help or advice, or even any links to tutorials that might help! Thank you in advance!

#include <iostream>

using namespace std;

int main()
{
   int array[20] = { 0 };

   for (int j = 0; j < 20; j++)
   {
      array[j] = rand() % 2;

      cout << (double)array[j] << endl;
  }

}




Aucun commentaire:

Enregistrer un commentaire