create a program that counts the number of occurence of an alphabet character counting letters in a string in c++
I have come across different codes but nothing is good to our professor, my professor wanted only
#include <iostream>
,#include<conio.h>
,using namespace std;
,letters that have been type by user is the letter that prints or outcomes
maybe this can help, here is my professor's previous code:
for(int y=0; y<=9; y++){
int counter=0;
for (int x=0; x<=99;x++){
if (refchar[y]==userchar[x]){
counter++;
}
}
cout<<refchar[y]<<"="<<counter <<"\n";
}
getch();
return 0;
}
And here is my code :
int main(){
string refchar="char alphabet[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N',
'O','P','Q','R','S','T','U','V','W','X','Y','Z'};
";
char userchar[500]="";
cout<<"Enter number:";
cin>>userchar;
for(int y=0; y<=9; y++){
int counter=0;
for (int x=0; x<=99;x++){
if (refchar[y]==userchar[x]){
counter++;
}
}
cout<<refchar[y]<<"="<<counter <<"\n";
}
getch();
return 0;
}