Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <ctime>
- #include <string>
- #include <cstdlib>
- using namespace std;
- void stringMix(char string1[], char string2[]);
- int main ()
- {
- char string1[50];
- char string2[50];
- char again;
- srand(time(0));
- cout << "Please input a string to randomize." << endl;
- cin.getline(string1, 50);
- do{
- stringMix(string1, string2);
- cout << "Would you like to randomize this string again? (Y/N)";
- cin >> again;
- }while (again == 'Y' || again == 'y');
- return 0;
- }
- void stringMix(char str1[50], char str2[50])
- {
- int length;
- length = strlen(str1);
- int position;
- for(int j = 0; j < length; j++)
- {
- str2[j] = 0;
- }
- for(int i=0; i < length; i++)
- {
- do
- {
- position = rand()% length;
- }
- while(str2[position] != 0);
- str2[position] = str1[i];
- }
- cout << "\nThe randomization of " << str1 << " is " << str2 << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement