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;
}

once you return the number, just put a for loop with that number and cout the alphabet that many times...

let me first check if i got the qs correctly.. you get a string of characters as i/p. it has chars from a to h and some chars might have more than one appearance in it .. so as of now u have been able to count the number of times each char is present in the i/p..rt? n u have to print them as many times... so for each char you send the entire i/p to the count fns n they tell you how many times its present... is that rt?

yea...im supposed to print the letter that many times it appears in i/p for each letter a to h

im gonna try ur idea now

This article has been dead for over six months. Start a new discussion instead.