I am writing a program that takes the alphabet and randomly mixes it up and compares it to the alphabet (you have to compile it to fully understand) i got as far as making a random mixed alphabet but sometimes letters are used more than once, what do i put in to make sure that no letter is used more than once?
here's what i got so far
Code:#include <iostream> #include <stdlib.h> #include <time.h> #include <math.h> using namespace std; void crypt(); int rand(int n); char *alphabet[26] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}; int main() { int i, n; srand(time(NULL)); while(1) { cout<< "type 1 start type 0 to exit"<<endl; cin>> n; if (n == 0) break; if ( n == 1) { for (i=1; i<=26; i++) crypt(); cout<<endl; cout<< "a b c d e f g h i j k l m n o p q r s t u v w x y z"<<endl; } } return 0; } void crypt() { int a; a = rand(26); cout<< alphabet[a]<<" "; } int rand(int n) { return rand() % n; }



LinkBack URL
About LinkBacks


