I cant get my summary_Count function to work i figured it out that it stops working on the for loop part here
The overall goal is to generate random charcters then count them and print how many a,b,c...ect. I made that for loop to count my letters but when i run it it stops right when it reaches the for loops. My full code is here its kind of mess though.
Code:
void summary_Count(char random[], int n)
{
int t=0;
int count[26]={0};
for(int a=0; a<=25; a++)
{
for(char i=97; char i=122; i++)
{
for(int j=0; j<=n; j++)
{
if (random[j]=i) count[a]++;
}}}
cout<<"\nSummary for the characters:"<<endl<<endl;
for(char ch='a';ch<='z';ch++)
{
cout<<ch<<" = "<<count[t] <<endl;
t++;
}
}
Code:
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <stdio.h>
#include <ctype.h>
using namespace std;
void parameters(int& seed,int& n);
char getChar(int seed);
void printCharcter(char random[],int n);
void summary_Count(char random[], int n);
int main()
{
bool repeat=true;
int seed;
int n;
char random[n];
char again;
srand(seed);
do{
parameters(seed, n);
for(int i=0; i<n; i++)
{
random[i]=getChar(seed);
}
printCharcter(random,n);
for(int j = 0; random[j] != '\0'; j++)
{
random[j] = tolower(random[j]);
}
summary_Count(random, n);
cout<<"\nDo you wish to try again? (Y/N) ";
cin >> again;
cout<<endl;
if (again == 'n' || again == 'N') repeat=false ;
else repeat=true ;
}
while(repeat==true);
system("PAUSE");
return 0;
}
void parameters(int& seed,int& n)
{
cout<<"Enter a seed number:";
cin>>seed;
cout<<"\nHow many charcters do you want generated:";
cin>>n;
if(n>100)
{
cout<<"Invlaid input, enter again"<<endl;
cin>>n;
}
cout<<endl;
}
char getChar(int seed)
{
char random = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"[rand() % 52];
return random;
}
void printCharcter(char random[],int n)
{
cout<<"Charcters generated are:"<<endl;
for(int i=0; i<n; i++)
{
if (i% 10== 0) cout<<endl;
cout<<random[i];
}
}
void summary_Count(char random[], int n)
{
int t=0;
int count[26]={0};
for(int a=0; a<=25; a++)
{
for(char i=97; char i=122; i++)
{
for(int j=0; j<=n; j++)
{
if (random[j]=i) count[a]++;
}}}
cout<<"\nSummary for the characters:"<<endl<<endl;
for(char ch='a';ch<='z';ch++)
{
cout<<ch<<" = "<<count[t] <<endl;
t++;
}
}
Comment