//This code gives randomly generated alphabets and if equal will
//cout the alphabet which is equal
1 #include <iostream>
2 #include <cstdlib>
3 #include <ctime>
4 using namespace std;
5 int main()
6 {
7 int a;
8 char array[10];
9 srand (time(0));
10 for (int i=0; i<10; i++)
11 {
12 a=rand() %26;
13 a=a+97;
14 array[i]=char(a);
15 }
16 for (int i=0; i<10; i++)
17 {
18 for (int j=0; j<10; j++)
19 {
20 if (array [i]==array [j]);
21 {
22 cout <<array[i] <<" " <<array[j];
23 }
24 cout << endl;
25 }
26 }
27 return 0;
28 } //program end
My question is how to check that randomly generated alphabets are equal e.g in 22 number line it should give output of equal alphabets if they are equal but it does not give equal alphabets what wrong in this code mention the wrong statement or help me how will i get right answer
When you say checking alphabets are equal, do you mean you are trying to generate two sets of ten letters and find out how many are equal between the sets? If you are, then this is what you need to do. (If not, what are you trying to do?)
//Pseudo code.
int i = 0, j = 0; //Just to iterate around loops
char array[10]; //Two separate arrays.
char array2[10];
for(i = 0; i < 10; ++i)
{
array[i] = A random letter.
array2[i] = A random letter.
}
//Then check each letter of each array for being the same.
for(i = 0; i < 10; ++i)
{
for(j = 0;, j < 10; ++j)
{
//is array[i] == array[j] ?
//If yes, then do something.
}
}