Here's a few you may want to think about:
Code:
#include <iostream>
#include <string> //include this - I'm not sure how I compiled without it.
//#include <time.h> //don't include this - .h standard headers have everything
//in the global namespace which could lead to name collision
#include <ctime> //include this one instead of <time.h>
//using namespace std; //why bring the whole std namespace in?
//You're only using two (soon to be three) things out of it
using std::string;
using std::cout;
using std::endl;
void Scramble(string &s)
{
int size = s.size(); //create a temp variable for size
//instead of calling the function multiple times inside the for loop
int scram_num=size*size;
srand(time(NULL));
for(int a=0;a<scram_num;a++)
{
int i=rand()%size;
char c=s[i];
s.erase(i,1);
int ii=rand()%size;
s.insert(ii,1,c);
}
}
int main()
{
string s="Country";
Scramble(s);
cout << s << endl; //you can cout a string; make sure to flush the output
return 0;
}
I once wrote a shuffle like this:
Code:
#include <algorithm>
void Shuffle(string &s)
{
int size = s.size();
srand(time(NULL));
for(int a=0;a<size-1;a++)
{
int i = rand()%(size-a)+a;
while(i==a)
i = rand()%(size-a)+a;
std::swap(s[a],s[rand()%(size-a)+a]);
}
}
It keeps from erasing and inserting so much. It also cuts down on the number of times through the scramble loop.