for this prob i have im supposed to cin a string of letters uppercased from A-H
for example if i cin ABACDEFGH
my prog should return them as such
AA
B
C
D
E
F
G
H
however i came up with functions which are able to count the number of each alphabet
but im stuck at being able to return them as above. i could only returnt the number of each letter
#include <iostream>
using namespace std;
int countA (char []);
int countB (char []);
int countC (char []);
int countD (char []);
int countE (char []);
int countF (char []);
int countG (char []);
int countH (char []);
const int MAX = 100;
int main()
{
char n [MAX];
cout << "Enter a string of letters A to H: " << endl;
cin.getline (n, MAX);
cout << countA (n) << endl;
cout << countB (n) << endl;
cout << countC (n) << endl;
cout << countD (n) << endl;
cout << countE (n) << endl;
cout << countF (n) << endl;
cout << countG (n) << endl;
cout << countH (n) << endl;
}
int countA (char n [])
{
int count = 0;
int letterA = 0;
while (n [count] != '\0')
{
if (n [count] == 'A')
letterA++;
count++;
}
return letterA;
}
int countB (char n [])
{
int count = 0;
int letterB = 0;
while (n [count] != '\0')
{
if (n [count] == 'B')
letterB++;
count++;
}
return letterB;
}
int countC (char n [])
{
int count = 0;
int letterC = 0;
while (n [count] != '\0')
{
if (n [count] == 'C')
letterC++;
count++;
}
return letterC;
}
int countD (char n [])
{
int count = 0;
int letterD = 0;
while (n [count] != '\0')
{
if (n [count] == 'D')
letterD++;
count++;
}
return letterD;
}
int countE (char n [])
{
int count = 0;
int letterE = 0;
while (n [count] != '\0')
{
if (n [count] == 'E')
letterE++;
count++;
}
return letterE;
}
int countF (char n [])
{
int count = 0;
int letterF = 0;
while (n [count] != '\0')
{
if (n [count] == 'F')
letterF++;
count++;
}
return letterF;
}
int countG (char n [])
{
int count = 0;
int letterG = 0;
while (n [count] != '\0')
{
if (n [count] == 'G')
letterG++;
count++;
}
return letterG;
}
int countH (char n [])
{
int count = 0;
int letterH = 0;
while (n [count] != '\0')
{
if (n [count] == 'H')
letterH++;
count++;
}
return letterH;
}