Actually, if you can figure out how to do it on integers, you can do it to ASCII based characters because they are represented by a identifier or number.
I am not actually not too sure on a randomizer code. And with this i would like to put them into a vector. but as i used rand_Num[x]= rand() % 26; for randomizing
with
1 2
#include <cstdlib>
#include <iostream>
are the libraries that I have and when i attempt to use the .length() function i receive an error:
request for member `length' in `rand_Num', which is of non-class type `int[26]'
my array that i have is int rand_Num[26]; and the rand_Num.length() gives me that error
Arrays are not classes, and therefore do not have member functions. You declared an array with 26 elements, so that's how many it will always have, you wouldn't need to use a length function when it has a constant size. However if you want this container to be scalable, the vector container is the one you should be using. It has the length() function you are looking for.
#include <cstdlib>
#include <iostream>
#include <conio.h>
usingnamespace std;
void PressAKeyToContinue()
{
int c;
cout<< "\n\nPress a key to continue..." ;
c = getch();
if (c == 0 || c == 224) getch();
}
int RandN()
{
srand(time(NULL));
typedeftemplate vector<int>numrand(26,0);//RIGHT HERE IS THE PROBELM
for(int x=0; x<numrand.length();x++)
{
numrand[x]=rand() % 26;
return(numrand[x]);
}
}
int main()
{
srand(time(NULL));
int rand_Num[26];
//double a=1.0, b=26.0;
for(int x =0; x<26; x++)
{
rand_Num[x]= RandN();
}
for(int x=0; x<26; x++)
{
cout<<rand_Num[x]<<" ";
}
for(int x=0; x<26; x++)
{
for(int y =x+1; y<26; y++)
{
if(rand_Num[x]>rand_Num[y])
{
int dummy=rand_Num[x];
rand_Num[x]=rand_Num[y];
rand_Num[y]=dummy;
}
}
}
cout<<"\n\n";
for(int x=0; x<26; x++)
{
cout<<rand_Num[x]<<" ";
}
PressAKeyToContinue();
return(0);
}
18 F:\Dev\main.cpp expected unqualified-id before "template"
18 F:\Dev\main.cpp expected `,' or `;' before "template"
19 F:\Dev\main.cpp `numrand' undeclared (first use this function)
15 F:\Dev\main.cpp `vector' undeclared (first use this function)
15 F:\Dev\main.cpp expected primary-expression before "int"
15 F:\Dev\main.cpp expected `;' before "int"
16 F:\Dev\main.cpp `numrand' undeclared (first use this function)