I've been working on a programming exercise and have run into a problem at the end. The goal is to write a program that outputs the number of each lower case letter in the programs own source file in a 2 column table using only 2 char variables and one int. Here is my code.
Yet when I run it I get a column of letter (as expected) but the second column only shows 0's after the first letter. I think it might have something to do with the scoping of the count variable, but I can't pin the problem down, any help is appreciated.Code:#include <iostream> #include <fstream> using namespace std; ifstream instream; int main () { for (char aval = 97; aval <= 122; aval++) { int count = 0; char b; instream.open("ASCII.cpp"); while (!instream.eof()) { instream.get(b); if (aval == b) { count++; } } cout << aval << " " << count << "\n"; instream.close(); } return 0; }