I am new to c++ programming. n my program I have to check the frequency of characters in the string but there is an issue. Whenever there are multiple same characters it first shows 1 and then 2 then 3.
#include <iostream>
using namespace std;
int main()
{
cout << "Array Enteries Occurance Checker \n";
int size_of_array = 20;
char string_array[size_of_array]{};
cout << "Please enter the string text : ";
cin.getline(string_array, size_of_array);
cout << "The Text Enter is : " << string_array << endl;
int counter = 0;
char character = 97;
for (character = 97; character <= 122; character++) {
counter = 0;
for (int i = 0; string_array[i] != '\0'; i++) {
if (string_array[i] == character) {
counter++;
cout << counter << " = " << character << endl;
}
}
}
cout << endl;
for (character = 65; character <= 90; character++) {
for (int i = 0; i < size_of_array; i++) {
if (string_array[i] == character) {
counter++;
cout << counter << " = " << character << endl;
}
}
counter = 0;
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire