mercredi 16 juin 2021

How do you generate a random string from an Array without causing any errors in C++? [duplicate]

I am making a dating site where your the only user and you swipe left and right on a computer-generated person. I made an array with a bunch of people's names that every time you type "Yes" or "No", the computer will suggest a new person with a different name, age, and bio. I have managed to make a random generator for the name array but I keep getting warnings. So I am wondering if there's another way for me to generate a random string in an array?

#include <iostream>
#include <istream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;

int main() {


    const int GIRL_SIZE = 5;
    srand(static_cast<unsigned>(time(0)));

    const int GIRL_BIO = 6;
    srand(static_cast<unsigned>(time(0)));

    string GirlsNames[GIRL_SIZE] = { "Gina", "Hailey", "Emma", "Charlotte", "Ava"};
    int GirlsAge[5] = { 18, 24, 36, 45, 60 };
    string GirlsBio[GIRL_BIO] = { "Hi, I love cars, reading is dope, self develop team!!!, work out every day!!", "Hey Bestie, I love Starbucks, I love shopping, white chicks is the best movie omg, I am so lazie, I love my dog Doodle",
    "Yo, it's your homegirl, I play basketball on a daily bro, Young MA is my favourite artist, I don't play no games, don't mess with me fam. ight peace",
        "Hello, I love programming, taking long walks on the beach, math is my favourite subject, I have high standards for school, OverWatch is my favourite game, I love reading comic books",
    "grr I am so angry at the world, it sucks and I hate it, I have black hair and I lot of tattoos and piercings (28 in total), I sit in my bed all day, black hoodies are my favourite clothes, Juice Wrld is my favourite artist." };

    string BoysNames[5] = { "Chad", "Boris", "Kyle", "George", "Austin" };
    int BoysAge[5] = { 18, 24, 36, 60 };
    string BoysBio[5] = { "Yello, I am a farmer, My favourite artist is Bob marly, I daily drive a Ford F-150, I love to work in the fields. Come take a smoke with me eh?",
        "Yo, it's your boy. I'm a frat boy and you can always come to my parties, working out is why I live, I work at LA Fitness, I have been arrested haha. Don't follow your dreams, follow my insta",
        "Hello, how are you? I am very shy, I work in the military, I live with my babushka, I fight bears as a hobby.", 
        "Good afternoon, I like to take long drives in Rodeo Drive, My dad gave me a small loan of 1 million dollars, I invest in crypto, mooncoin is the next big wave,  my favourite food is caviare. imma go now, cheerios",
        "Hello, I am a programmer, I like to play video games, League of Legends is my favourite game, ok bye"
    };
    
    string youInto[3] = { "Boy", "Girl", "Both" };

    string gender;
    std::cout << "Gender: ";
    std::cin >> gender;
    
 
    if (gender == "boy") {
        for (int i = 0; i < GIRL_SIZE; i--) {
            int index = rand() % GIRL_SIZE;

            string temp = GirlsNames[i];
            GirlsNames[i] = GirlsNames[index];
            GirlsNames[index] = temp; 

            for (int i = 0; i < GIRL_SIZE; i--) {
                std::cout << GirlsNames[i] << endl;
            }
        }

       /* for (int i = 0; i < GIRL_BIO; i--) {
            int index = rand() % GIRL_BIO;

            string temp1 = GirlsBio[i];
            GirlsBio[i] = GirlsBio[index];
            GirlsBio[index] = temp1;

            for (int i = 0; i < GIRL_BIO; i--) {
                std::cout << GirlsBio[i] << endl;
            }
        } */
    }
    else if (gender == "girl") {
        // Code here
    }

};



Aucun commentaire:

Enregistrer un commentaire