jeudi 28 octobre 2021

How to randomize char symbols in c++

I just started learning C++. I want my code to print symbols in random order using array, why doesn't it work?

#include<iostream>
#include<ctime>
#include<cstdlib>

using namespace std;


int main() {
    const int rnd = 4;
    char arr[rnd] = { 'H', 'E', 'L', 'L' };
    srand(time(NULL));
    for (int i = 0; i <= arr[rnd]; i++) {
        arr[i] = rand();
        cout << arr[i];
    }
    return 0;
}



Aucun commentaire:

Enregistrer un commentaire