need help for this code

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: need help for this code

 
0
  #11
Sep 25th, 2008
Here is some sample code which may be of use to you:

  1. #include <iostream>
  2. #include <fstream>
  3. #include <algorithm>
  4. #include <ctime>
  5. #include <string>
  6. #include <sstream>
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.  
  13. string line;
  14. cout << "Please insert the words that you want to scramble" << endl;
  15. getline ( cin, line, '\n' );
  16. string array[100];
  17.  
  18. stringstream ss ( line );
  19.  
  20. string word;
  21. string newLine = "";
  22.  
  23. int i = 0;
  24. while ( ss >> word )
  25. {
  26. array[i] = word;
  27. i++;
  28. }
  29. char ans;
  30.  
  31. do
  32. {
  33. cout << "\nReshuffle (Y/N)" << endl;
  34. cin >> ans;
  35.  
  36. srand ( unsigned ( time ( NULL ) ) );
  37. random_shuffle ( array, array + i );
  38.  
  39. //print shuffled sentence
  40. cout << "\n";
  41. for ( int j = 0 ; j < i; j++ )
  42. {
  43. cout << array[j] << " ";
  44. }
  45. }while ( ans != 'N' );
  46. system ( "PAUSE" );
  47. return 0;
  48. }

You might not be able to use stringstreams to separate your sentence into bits...

output
  1. Begin file creation
  2. Please insert the words that you want to scramble
  3. HELLO, I AM A FOOL!
  4.  
  5. RESHUFFLE (Y/N)
  6. Y
  7.  
  8. A FOOL! HELLO, I AM
  9. RESHUFFLE (Y/N)
  10. Y
  11.  
  12. I AM FOOL! A HELLO,
  13. RESHUFFLE (Y/N)
  14. Y
  15.  
  16. A HELLO, AM I FOOL!
  17. RESHUFFLE (Y/N)
  18. Y
  19.  
  20. I FOOL! HELLO, A AM
  21. RESHUFFLE (Y/N)
  22. Y
  23.  
  24. AM I FOOL! HELLO, A
  25. RESHUFFLE (Y/N)
Last edited by iamthwee; Sep 25th, 2008 at 2:39 pm.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC