Hi, Good day.
I had just learned C++ programming for 3 months.
I am making a program of a simple Jackpot. It's a school project actually.
I manage to get random alphabet output and I am to find the number of time the alphabets are repeated after they are generated.
I am facing a problem where the count for the repeated alphabet tends to continue to increase even after they are scanned and I can't manage to solve it.
RN_no=0;
for (i=0; i<7; i++)
{
for (k=i+1;k<7;k++)
{ if (ran[i]==ran[i-1]) {break;}
//this is to make sure that the alphabet of 'i' is not equals to the
one before so that it won't double count
else { if (ran[i]==ran[k])
{
RN_no=RN_no+1; //this is where the count is increase
if there is a similar alphabet.
}
}
}
}
printf ("\nRepeated Alphabet = %d",RN_no);
My problem is that the alphabet will continue to be counted even after if it is counted, eg:
A A B B A G A
*supposingly there are only 4 repeatings, A 3 times and B 1 time
my code shows 5 times as the 'A' after the 'B' is still used to compared with
the last 'A'
Hope that someone can help me out with this issue please...
Thank you.