our task is to show the histogram in a vertical orientation like this:
Sample Input/Output
Enter a string: waka waka fifa
Histogram for waka waka fifa
*
*
* * * *
* * * * *
a f i k w
I have here my code, but the output of this is in horizontal orientation.. what am i going to do to make this vertical? the sanple output of this is:
Sample Input/Output
Enter a string: waka waka fifa
Histogram for waka waka fifa
a * * * * *
f * *
i *
k * *
w * *
# include <iostream>
# include <string>
using namespace std;
main()
{
string letters="abcdefghijklmnopqrstuvwxyz";
string sentence;
string::size_type slen;
int name[26];
char ans;
do{
for(int s=0; s < 26; s++)
name[s] = 0;
cout<<"Enter a string (no space please): ";
cin>>sentence;
cout<<endl;
cout<<"Histogram for "<<sentence<<endl;
// slen = sentence.length();
for(int t=0; t<26; t++){
for(int sl=0; sl<slen; sl++){
if (letters[t] == sentence[sl])
name[t]++;
}
}
for (int r=0; r < 26; r++){
if (name[r] > 0){
cout<<letters[r]<<" ";
for(int i=0; i <name[r]; i++)
cout<<"*";
cout<<endl;
}
}
cout << endl << "another? [y/n]: ";
cin >> ans;
cout<<endl;
}while(ans != 'n');
cout<<"\n\nPress any key and ENTER to EXIT! ";
char response;
cin>>response;
return 0;
}