letter-counting program

closed account (4L860pDG)
I'm writing a program that is supposed to count the number of hexadecimal digits (a, b, c, d, e, and f's) in a line of text. The output should look like this:

Enter a line of text:

number of a's:
number of b's:
number of c's:
number of d's:
number of e's:
number of f's:
--------------
total hex digits:

I'm getting this output, but it's not giving me the correct amount of times each letter occured. Help??

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
    cout << "CS110" << endl << endl;
    while(true)
    {
    cout << "Enter a line of text: ";
    string s;
    getline(cin,s);
    if(s == "")break;
    cout << endl;
        {
        int i = 0;
        int a = s.find("a", i);
        int b = s.find("b", i);
        int c = s.find("c", i);
        int d = s.find("d", i);
        int e = s.find("e", i);
        int f = s.find("f", i);
            {
            cout << fixed << setprecision(7);
            cout << "Number of a's: " << setw(7) << a << endl;
            cout << "Number of b's: " << setw(7) << b << endl;
            cout << "Number of c's: " << setw(7) << c <<endl;
            cout << "Number of d's: " << setw(7) << d << endl;
            cout << "Number of e's: " << setw(7) << e <<endl;
            cout << "Number of f's: " << setw(7) << f << endl;
            cout << "-------------- " << endl;
            cout << "Total hex digits: " << setw(4) << a+b+c+d+e+f << endl << endl;
            }
        }
    }
Topic archived. No new replies allowed.