Hello all, what I'm trying to do is after counting all the letters in my file I'm getting all the percentages of each letter. Next I have to have a running total for the percentages. For example if
and so on throughout the whole alphabet. To do this I was trying to have a seperate array in the last for loop that would store all the single percantages...but the following is not working:Code:A: 0.0860 and B: 0.0151 than the running total for B would be (.0860+.0151) or B: 0.1011
so two questions: is there a way to store the percentages only into a seperate array?Code:percentageArray[i] = lettersArray[i]/(double)sum;
here is the part of the code that deals with this:
thanks,Code:for ( i=0; i<LIMIT; i++ ) { lettersArray[i] = 0; } cout << "The input file contains: \n"; while( inStream >> c) { lettersArray[toupper(c)]++; //count each instance of every character //cout << c << " "; } cout << endl; cout << "The number of each letter in the input file (darwin.txt) are: \n"; for( i='A'; i<='Z'; i++ ) //to get only alphabetical characters { cout << (char)i << ":" << setw(4) << setfill(' ') << lettersArray[i] << "; " ; sum += lettersArray[i]; //get total of all characters } cout << "\n\nThe percentages for the input file are: \n"; //set the percentages for input for( i='A'; i<='Z'; i++) { cout << (char)i << ":" << lettersArray[i]/(double)sum<< "; " ; }
axon



LinkBack URL
About LinkBacks


