My program is having an error on the following lines w/ red font. It says invalid types 'int[int]' for array subscript... pls help I'm not sure how to solve this.

*********This is actually how my program works*********

Read in a line of text and output the number of words in the line and the number of occurrence of each letter. Output the letters in alphabetical order
(e.g) I say Hi.
Should produce output similar to the ffg:
3 words
1 a
1 h
2 i
1 s
1 y
i SAY hI
Before asking for the choices the user should prompt to enter a password (3 tries only). If the user try to enter 3 incorrect password the program will be terminated. Also, ask the user to repeat the process.

#include <iostream>
#include <string>
#include <ctype.h>
#include <cstdlib>
#include <stdio.h>
#include <windows.h>
#include <conio.h>

using namespace std;

int main()
{

	string str;
	char alphaLet[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
	int ctr, ctc;
	int numChar = 0, numWrd = 1;
	int ctrLet;

	cout << "Input Valid Sentence:\n";
	getline(cin,str);

	numChar = str.length();
	
	
	for(ctr = 0; ctr < numChar; ctr++)
	{
		if(str.at(ctr) == ' ')
		numWrd++;
	}
	
	cout << "\nWords: " << numWrd << endl;

	
	for(ctr = 0; ctr < numChar; ctr++)
	{
		for(ctc = 0; ctc < 26; ctc++)
		{
		
			if(str.at(ctr) == alphaLet[ctc])
			ctrLet[ctc]++;
		
		}
	
	}


	for(ctr = 0; ctr < 26; ctr++)
	{
		if(ctrLet[ctr] > 0)
			cout << ctrLet[ctr] << " " << alphaLet[ctr] << endl;
	
	}
	
	cout << "\n\n";
	

	for(ctr = 0; ctr < numChar; ctr++)
	{


		if(isupper(str.at(ctr)))
		(str.at(ctr))=tolower(str.at(ctr));
		else if(islower(str.at(ctr)))
		(str.at(ctr))=toupper(str.at(ctr));
	
	
	}

	cout << endl << str;

	cout << "\n\n";
system ("pause");
return 0;

}

>ctrLet[ctc]++;
ctc is an int, which is fine. But ctrLet is also an int. The int type does not support indexing.

int ctrLet;

if(ctrLet[ctr] > 0)
cout << ctrLet[ctr] << " " << alphaLet[ctr] << endl;

ctrlet is an integer and it is not declared as an array.

ctrlet is an integer and it is not declared as an array.

i tried to make ctrLet an array like this...

int ctrLet[];

but still it didn't work. it says unknown array size but how should i change it?

Arrays should be given constant size while declaration. See this

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.