#include <iostream>
usingnamespace std;
int readData(int &charArray, int &counter);
void printMostFrequent(int &charArray, int &counter);
int main()
{
int charValues[128];
for(int i = 0; i <= 128; i++)
charValues[i] = 0;
int count = 0;
readData(charValues, count);
printMostFrequent(charValues, count);
return 0;
}
int readData(int &charArray, int &counter)
{
int index = 0;
char charIn;
cin >> charIn;
while(charIn != EOF)
{
index = static_cast<int>(charIn);
charArray[index] += 1;
counter += 1;
cin >> charIn;
}
return counter;
}
void printMostFrequent(int &charArray, int &counter)
{
char printChar;
for(int i = 0; i <= counter; i++)
{
if(static_cast<double>(charArray[i]) / static_cast<double>(counter) > 0.025 && static_cast<double>(charArray[i]) / static_cast<double>(counter) < 0.06)
{
printChar = static_cast<char>(charArray[i]);
cout << printChar << "\t" << charArray[i] << endl;
}
}
}
g++ -o proj5Code.exe proj5Code.cpp
proj5Code.cpp: In function âint main()â:
proj5Code.cpp:13: error: invalid initialization of non-const reference of type âint&â from a temporary of type âint*â
proj5Code.cpp:4: error: in passing argument 1 of âint readData(int&, int&)â
proj5Code.cpp:14: error: invalid initialization of non-const reference of type âint&â from a temporary of type âint*â
proj5Code.cpp:5: error: in passing argument 1 of âvoid printMostFrequent(int&, int&)â
proj5Code.cpp: In function âint readData(int&, int&)â:
proj5Code.cpp:26: error: invalid types âint[int]â for array subscript
proj5Code.cpp: In function âvoid printMostFrequent(int&, int&)â:
proj5Code.cpp:37: error: invalid types âint[int]â for array subscript
proj5Code.cpp:37: error: invalid types âint[int]â for array subscript
proj5Code.cpp:39: error: invalid types âint[int]â for array subscript
proj5Code.cpp:40: error: invalid types âint[int]â for array subscript
Compilation exited abnormally with code 1 at Tue Nov 12 20:31:02