I've written a code to make a character histogram of a sentence that is entered. However, i'm trying to make it so I can select the character to show the histogram.
Enter String Upto 20 Characters
"Very Nice Day"
Enter letter to show histogram for
e
e 2
My problem is that the program keeps repeating the alphabet for the length of the string. For example. 7 characters.. 7 repeats. I don't know how to fix my loop to correct this.
Also anywhere i try to implement the character to show histogram for code. It repeats too.
//Histogram For Selected Character
#include <iostream>
#include <fstream>
usingnamespace std;
int main()
{//start main 1s
char string;
int i;
int newstar[26]={0};
int sum[26]={0};
int star;
char letter;
cout << "Enter String Upto 20 Characters\n";
do
{//start do 2s
start:
{
string=cin.get();
string=tolower(string);
if(isalpha(string))
{//4s
for (i=97;i<123;i++)
{//5s
if (string==i)
{//6s
sum[string-97]++;
newstar[i-97]=sum[i-97];
}//6e
cout<<(char)i<<" "<<sum[i-97];
for (star=0; star<newstar[i-97]; star++)
{
cout<<"";
}
cout<<endl;
}//5e
}//4e
}//end do 2e
}
while (string != EOF);
}//end main 1e