The idea is to get a sentence of words and then scramble the middle letters of each word without altering the position of the word in the sentance. So for example, the user inputs: Programming is very interesting! the output should be: Pogrmarmnig is vrey itenrseitng! So far, i have been able to write a program that scrambles the letters of only 1 word and would like to see if someone would be friendly enough to help me get an idea of what i can do to modify a string of words. Here is my code:
#include <iostream>
#include <cstring>
using namespace std;
string switcharoo(string s){
int frst = 1;
int lst = s.size()-1;
for (int i = frst; i < lst; i++){
srand (time(NULL));
int j= 1+rand() % lst;
char t = s;
s = s[j];
s[j] = t;
}
return s;
}
int main(){
string stmt;
cout << "type a sentance: ";
getline(cin, stmt);
stmt = switcharoo(stmt);
cout << stmt;
return 0;
}