Help - what am I doing wrong???

Hey... I'm not sure what I'm doing wrong here - REALLY need this done soon, as I have this due tomorrow!!!


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
35
36
37
38
39
40
41
42
43
  #include <iostream>
using namespace 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
why are you using static casts?? You can only use static_casts on pointers.

on line 18, make that function void, no need t return a value that is already returned through a reference arg.

When declaring prototypes at the top, you should not declar your variables. It's good practice.

void reverse_string(string&);

a for loop ex to retrieve what you want from the file:

for(unsigned int x = 0; ((x < whatever) && in.good()); x++){}

you should study up on for loops.
Thanks!!!
You will be using all of that for the rest of your class, I seriously suggest you try to understand it (thoroughly).
Topic archived. No new replies allowed.