Counting Characters

Can someone please help me with this

You are given several lines input data, each line containing exactly 25 alphabetic
characters, A through J, only. The characters may be upper or lower case. These are to
be read from in an input file. Use nested while loops. The outer while loop controls the
processing of the lines. Read lines until the first character of the line is a ‘?’ then stop.
The inner while loop (counting loop) controls the 25 characters on each line. As you
process each line you will read the characters one at a time and count the number of
characters of each type. At the end of each, line print out a list of the number of each
character. Upper case and lower case of each character are to be counted together. You
must use a switch statement to select between the characters and count them. Your
report should look as shown below. (Solution for first line.) Use file I/O.


I am suppose to use infile.()
and my input data is abcabcabcabcabcabcabcabca
aABBEEdeddEDGFFfefeabacbI
ABEADFHGJKDIIABCDFGEIHHID
ABDDEFGHIabcdefghiABCDEFG
HIHIHIHIHIHIaddddadfffiii
Abcdefghiabcdefghiabr5efg
AAAAAAAAAAaaaaaaaaaaAAAAA
BadCadDadHadFadFeeFiBegHi
abDCIIjJJiJEFEfghijgheaJi
AAB?ababijijIHIHEEddEdffF
?

#include<iostream>
#include<fstream>


using namespace std;

int main()
{
ifstream infile;
ofstream outfile;
infile.open("Text.txt");
outfile.open("output.txt");


int count, operation;
count = 0;
int LetSum = 0;
char x;
x = infile.get();
cin >> operation;

while (x != '?')
{
while (count <= 24)
{
switch (operation)
{
case 'a': case 'A':
{
LetSum += x;
}

}



}


}
infile.close();
outfile.close();
return 0;
}
Last edited on
Please use code tags. http://www.cplusplus.com/articles/jEywvCM9/
You can edit your post, highlight your code and click the <> button on the right.

I'd recommend storing the count of each letter in an array.
1
2
3
const int NUM_LETTERS = 10;
int letter_count[NUM_LETTERS] = { 0 };
// a/A is index 0, b/B is index 1, c/C is index 2, etc... 
Topic archived. No new replies allowed.