I need help with errors I am getting with my program that is suppose to take in lines of text and out put the number of letters to the user. I have a lot these errors

expected primary-expression before ' ' token

Attachments
/* Author: 
   UserId #:
   Creation Date: 
   Modification Date:
   
   Course:   
   File name: letterCount.cpp    
   
   Inputs: Three lines of text 
   Ouputs: Table displaying how many of each letter are in the lines of text, plus non-alphebetical characters  
   Formulas: 
   Purpose: To tell the user how many letters and non-alphebetical characters in a line of text.   

 */

#include <iostream>
#include <cctype>
#include <iomanip>

using std::cout;
using std::cin;
using std::endl;
using std::setw;

const int Max_Size = 80;
const int Max_Lines = 10;
int i;
int z;
int n;

void readLine (char letter[][Max_Size], int Max_Lines, int& size);
void conversion (int size, char lines [Max_Lines][Max_Size], char alphabet[27] = "abcdefghijklmnopqrstuvwxyz", int alphacount [27] = {0});
void displayTable (int alphacount [27] = {0}, char alphabet[27] = "abcdefghijklmnopqrstuvwxyz");

int main()
{
char lines [Max_Lines][Max_Size];
char letter [10] [Max_Size];
int size;
int alphacount [27] = {0};
char alphabet[27] = "abcdefghijklmnopqrstuvwxyz";

readLine (letter, Max_Lines, size);
conversion (size, lines, alphabet, alphacount);
displayTable (alphacount, alphabet);

return 0;
}


void readLine (char letter[][Max_Size], int Max_Lines, int& size)
{  
  cout << "How many lines of text are you entering? ";
  cin >> size; 
  cout << "Type in "<< size <<" lines of text, pressing enter after each line. \n";
  if (size <= Max_Lines)
  {
    for (int i = 0; i <= size; i++)
    {
      cin.getline (letter[i], Max_Size);
      //cout << letter[i];
    }
  }
  else
   {
   cout << "You have entered too many lines of text, the limit is " << Max_Line << ".";
   }
  cout << endl;
}

void conversion (int size, char lines [Max_Lines][Max_Size], char alphabet[27] = "abcdefghijklmnopqrstuvwxyz", int alphacount [27] = {0})
{
for(i=0;i<26;i++)
{
  for(n=0;n<size;n++)
  {
    for(z=0;lines[n][z]!= '\0'; z++)
    {
      lines[n][z]= tolower(lines[n][z]);
      
      if (lines[n][z]== alphabet[i])
      {
        alphacount[i]++;
      }
    }
  }
}
}

void displayTable (int alphacount [27] = {0}, char alphabet[27] = "abcdefghijklmnopqrstuvwxyz")
{
if(!isalpha(line[n][z]))
{
  countAlpha[26]++;
}

cout<< setw(5)<< "Letter"
    << setw(10)<< "Count"
    << endl;

for(i=0;i<26;i++)
{
  cout<< setw(5)<< alphabet[i]
      << setw(10)<< countAlpha[i]
      << endl;
}
cout<< "There were " << countAlpha[26] << " non-alphabetic characters!";
}
void conversion (int size, char lines [Max_Lines][Max_Size], char alphabet[27] = "abcdefghijklmnopqrstuvwxyz", int alphacount [27] = 0);
void displayTable (int alphacount [27] = 0, char alphabet[27] = "abcdefghijklmnopqrstuvwxyz");

Remove the { and } around the default parameters. That will cause the int array to be NULL pointers if the calling function doesn't supply the array. For example

int foo(int ary[4] = 0)
{
    if( ary != NULL)
    {
        for(int i = 0; i < 4; i++)
        {
            cout << ary[i] << "\n";
        }
    }
    cout << "All done\n";

    return 1;
}

int main()
{
       foo();
}

Check your variable typing (i.e. Max_Lines instead of Max_Line in line 66 but I also read countAlpha instead of alphacount elsewhere).

Also, you should pass lines as argument to the function displayTable.
You have an out-of-boundaries access for your lines array - be careful how you play with size <= Max_Lines and how you declared lines itself char lines [Max_Lines][Max_Size]; . Notice that lines is also accessed in displayTable function at line 92 if(!isalpha(lines[n][z])) . Ask yourself: what value does n has?

EDIT: Imho it's better to post your code with the help of code tags instead of providing it as an attachment for programs of this size - but this is just a suggestion

First I would like to say thanks to everyone's help I have cut down my errors tremendously. Second I am really struggling with this class and I am now at the point to where I'm just trying to pass and leave with the little bit of knowledge I've gained. That being said some of the advice given is beyond me, and though I'm sure you covered these error codes already here is what I'm getting specifically.

letterCount2.cpp: In function `void conversion(int, char (*)[80], char*, int*)':
letterCount2.cpp:72: error: default argument given for parameter 3 of `void conversion(int, char (*)[80], char*, int*)'
letterCount2.cpp:32: error: after previous specification in `void conversion(int, char (*)[80], char*, int*)'
letterCount2.cpp:72: error: default argument given for parameter 4 of `void conversion(int, char (*)[80], char*, int*)'
letterCount2.cpp:32: error: after previous specification in `void conversion(int, char (*)[80], char*, int*)'
letterCount2.cpp: In function `void displayTable(char (*)[80], int*, char*)':
letterCount2.cpp:91: error: default argument given for parameter 2 of `void displayTable(char (*)[80], int*, char*)'
letterCount2.cpp:33: error: after previous specification in `void displayTable(char (*)[80], int*, char*)'
letterCount2.cpp:91: error: default argument given for parameter 3 of `void displayTable(char (*)[80], int*, char*)'
letterCount2.cpp:33: error: after previous specification in `void displayTable(char (*)[80], int*, char*)'

You should remove default values for default arguments from your functions definitions.

For example this code

#include <iostream>

int myfunction(int one, int two = 2);

int myfunction(int one, int two = 2) {
	return one + two;
}

int main(void) {
	std::cout << myfunction(1) << std::endl;
	std::cout << myfunction(1, 3) << std::endl;
	return EXIT_SUCCESS;
}

Would result in the following compile errors:

test.cpp: In function ‘int myfunction(int, int)’:
test.cpp:5: error: default argument given for parameter 2 of ‘int myfunction(int, int)’
test.cpp:3: error: after previous specification in ‘int myfunction(int, int)’

while this code (without " = 2 " default value in function definition)

#include <iostream>

int myfunction(int one, int two = 2);

int myfunction(int one, int two) {
	return one + two;
}

int main(void) {
	std::cout << myfunction(1) << std::endl;
	std::cout << myfunction(1, 3) << std::endl;
	return EXIT_SUCCESS;
}

will compile fine

Hey thanks I got it to compile and run, one obstacle done now to the next, lol. For some reason its not counting the letters correctly in the lines of text i type? I believe that would have something to do with the conversion function or maybe not reading in all the lines of text. Any help would be appreciated.

void readLine (char letter[][Max_Size], int Max_Lines, int& size)
{  
  cout << "How many lines of text are you entering? ";
  cin >> size; 
  cout << "Type in "<< size <<" lines of text, pressing enter after each line. \n";
  if (size <= Max_Lines)
  {
    for (int i = 0; i <= size; i++)
    {
      cin.getline (letter[i], Max_Size);
      //cout << letter[i];
    }
  }
  else
   {
   cout << "You have entered too many lines of text, the limit is " << Max_Lines << ".";
   }
  cout << endl;
}
void conversion (int size, char lines [Max_Lines][Max_Size], char alphabet[27], int alphacount [27])
{
for(i=0;i<26;i++)
{
  for(n=0;n<size;n++)
  {
    for(z=0;lines[n][z]!= '\0'; z++)
    {
      lines[n][z]= tolower(lines[n][z]);
      
      if (lines[n][z]== alphabet[i])
      {
        alphacount[i]++;
      }
    }
  }
}
}

Thanks everyone I got it working correctly

PS: I should have come here for help earlier in my semester

This article has been dead for over six months. Start a new discussion instead.