Question #43788

Write a program that creates two string arrays, one to store names of 5 boys and another to
store names of 5 girls. Read the names from the user. The program then matches the boys
and the girls randomly and displays the 5 pairs of matched couples.

Your program should not repeat any boy’s or girl’s name in the matching.

Expert's answer

#include <iostream>#include <string>#include <algorithm> // for random_shuffle()#include <ctime> // for time()#include <cstdlib> // for srand() using namespace std; int main(){    stringboy[5] = {};    stringgirl[5] = {};     // read boys name    for (int i = 0; i < 5; i++)    {       cout << "Enter boy name: ";       cin >> boy[i];    }     // read girls name    for (int i = 0; i < 5; i++)    {       cout << "Enter girl name: ";       cin >> girl[i];    }     // for new random eachtime    srand(time(0));    // girls randomizing   random_shuffle(&girl[0], &girl[5]);     for (int i = 0; i < 5; i++)    {       cout << "Pair " << i + 1 << ": " << boy[i] << " & " << girl[i] << endl;    }     return 0;}
LATEST TUTORIALS
APPROVED BY CLIENTS