English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories
0

I have to take in a a string and scramble it 5 times, using string methods. I have to separate it using 2 radnom num's, and into three parts. It won't execute for some reason. Any help will be appreciated. Here's the code:
cout< cout<<"Enter a phrase to shuffle: ";
getline(cin,phrase_input);

for(int i = 0;i <= 5;i++)
{
beg = phrase_new.substr(0,random_one);
mid = phrase_new.substr(random_one,random_two - random_one);
endphr = phrase_new.substr(random_two,phr_len - random_two);

shuffled_phrased+= endphr;
shuffled_phrased+= beg;
shuffled_phrased+= mid;

}
cout<

2007-01-27 08:02:35 · 2 answers · asked by Anonymous in Computers & Internet Programming & Design

2 answers

first, I assume that somewhere you are copying phrase_input into phrase_new somewhere and just didnt show the code.

second, make sure your random_one and random_two are not greater than the length of the string phrase_new.

third, to loop 5 times, your "for" loop should be "for(int i = 0; i < 5; i++)"

fourth, you need to copy shuffled_phrased back into phrase_new at the end of your loop, so you can repeat the operations on it again.

2007-01-28 01:17:10 · answer #1 · answered by justme 7 · 0 0

Do you know how to use a debugger?
If not, I suggest you learn.

A debugger will help you to pinpoint a problem to a specific line of code. Learn to step through the code and verify it is doing what it is supposed to be doing.

Learn to use breakpoints and the call stack.

2007-01-27 16:19:56 · answer #2 · answered by Anonymous · 0 0

fedest.com, questions and answers