input string and randomize the string

Hey whats up??

I need some help I am trying to change this code but having issues on the correct way to take the input of a string and rearrange the letters(randomize) so that the word displays in a mixed up form.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
 #include <iostream>     // std::cout
#include <algorithm>    // std::random_shuffle
#include <vector>       // std::vector
#include <ctime>        // std::time
#include <cstdlib>      // std::rand, std::srand
#include <string>


using namespace std;

std::string mysteryWord;
std::string scrambleWord;
std::string guessWord;

void mixUp(string)//built in function to randomly shuffle character is a string
{
    random_shuffle ( scrambleWord.begin(), scrambleWord.end() );

    //int myrandom (int i) { return std::rand()%i;}
    //for(string i = scrambleWord.begin(); i< scrambleWord.end();i++)
}

int main() {
    int count =1;

    
    //srand((unsigned)time(0));
    std::cout <<"Enter a mystery word"<<endl;
    std::cin >> mysteryWord;
    
    scrambleWord = mysteryWord;
    mixUp(scrambleWord);
    
   
    cout<<"Guess the word:  ";
    std::cout << scrambleWord<<endl;
    
    cin>> guessWord;
    
    while(count != 7 && guessWord != mysteryWord)
    {
        cout<< "Try again"<<endl;
        count++;
        cin>> guessWord;
    }
    
    if(mysteryWord == guessWord)
    {
        cout << "You WIN"<< endl;
    }

   if (count==7)
    {
        cout << "You Lose to many tries"<<endl;
        std::cout << "The mystery word is-->>"<< mysteryWord<<endl;
    }
}
You are passing to the function mixup by value, so it is working on a copy of the string. You should pass by reference. You've also not put the parameter name in the function parameter list.

Try void mixUp(string& scrambleWord) on line 15, and then go back and read up on how to write functions.
Topic archived. No new replies allowed.