Compile error

I am making a program for school, and I CANNOT figure out my compile errors. I don't want you guys to have to write the program for me, but could you please try to help me compile the code? Thanks in advance, everyone.

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Pe1.cpp
// Programming Exercise #1
// Description: Read all records within a file, the contain the amount of consonants // and vowels input by the user, 
// and read them in alphabetical order. 

#include <iostream>
#include <fstream> //required for file reading 
using namespace std;

int main()
{
  //Initialize variables 
  string value; 
  int numCon = 0;
  int numVow = 0;
  char first = "";
  int vCount = 0;
  int cCount = 0;
  
  ifstream inFile; 
  inFile.open("/usr/share/lib/dict/words");
//  if (!inFile)     // ensure that no error occurred 
  if (inFile.fail())     // ensure that no error occurred 
  {
    cout << "Error opening file - quit\n";  // Ooops - handle error 
    return 1; // exit with error status
  }

        // no error - read every record in file

    cout << "File opened successfully\n";
    cout << "Enter consonants: \n" << endl;
    cin >> numCon; //get number of consonants
	cout << "Enter vowels: \n" << endl;
	cin >> numVow; //get number of vowels
	cout << "Enter first character: \n" << endl;
	cin >> first;
   
	while (inFile >> value) {
      //cout << value << endl;
		if (value.at(0) != first){
			continue;
		}
		for (i=0; i < value.size(); i++){
			if (isalpha(value.at(i))){
				if (value.at(i) = "A" ||
					value.at(i) = "a" ||
					value.at(i) = "E" ||
					value.at(i) = "e" ||
					value.at(i) = "I" ||
					value.at(i) = "i" ||
					value.at(i) = "O" ||
					value.at(i) = "o" ||
					value.at(i) = "U" ||
					value.at(i) = "u"){
					vCount++;
				} else {
					cCount++;
				}
			}
		}
		if (vCount == vowel && cCount == con){
			cout << value <<endl; //Display word
			vCount = 0;
			cCount = 0;
		}
	}
    inFile.close();
	cout << "PROGRAM ENDS: \n" << endl;
  return 0;
}  
It would help knowing what the errors are and in which lines they occur...
but it looks like you're mixing up = and ==.
Last edited on
I read on this site somewhere that to see what you learned after taking some tutorials on the basics of C++ was to look at other peoples code...that being said I don't know how much help I can be considering I am a beginner and someone can please correct me if I am wrong...but I see a couple issue with variables that you haven't defined/declared. One being "i" as you used it in

for (i=0; i < value.size(); i++){
if (isalpha(value.at(i))){
if (value.at(i) = "A" ||
value.at(i) = "a" ||
value.at(i) = "E" ||
value.at(i) = "e" ||
value.at(i) = "I" ||
value.at(i) = "i" ||
value.at(i) = "O" ||
value.at(i) = "o" ||
value.at(i) = "U" ||
value.at(i) = "u"){
vCount++;
} else {
cCount++;
}
}
}

But it doesn't have a type assigned to it (ie. int, char, float) Also I don't know what compiler you are using but the variable first you are using looks wrong and this might be my compiler talking (Code::Blocks) because I tried defining a variable like that once b4 and it errored on me.

Also the varible vowel and con don't look to be defined either. Don't know if that helps you at all =/
The teacher is having me send the code to a website to compile. It doesn't return a specific error line or anything, it simply tells me that it didn't compile. Any other thoughts? I actually contacted him and he said to keep searching and I can meet him tomorrow if no one could help, but I'd have a penalty for a late assignment.

Thanks for pointing out some errors for me. I'm much more used to object oriented stuff, and c++ is pretty foreign to me.
Its giving me an invalid comparison between a pointer and an int for this code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
if (value.at(i) = "A" ||
					value.at(i) == "a" ||
					value.at(i) == "E" ||
					value.at(i) == "e" ||
					value.at(i) == "I" ||
					value.at(i) == "i" ||
					value.at(i) == "O" ||
					value.at(i) =="o" ||
					value.at(i) == "U" ||
					value.at(i) == "u"){
					vCount++;
				} else {
					cCount++;
				}


Should I write it as value.at(&i)?
change
if (value.at(i) = "A" ||
to
if (value.at(i) == "A" ||
I got that one. Thank you though. I'm still throwing an error. I suck at debugging c++. Sorry, Ladies and Gents.
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Pe1.cpp
// Programming Exercise #1
// Description: Read all records within a file, the contain the amount of consonants // and vowels input by the user, 
// and read them in alphabetical order. 

#include <iostream>
#include <fstream> //required for file reading 
using namespace std;

int main()
{
  //Initialize variables 
  string value; 
  int numCon = 0;
  int numVow = 0;
  char first; ///////////////////////////////////////////
  int vCount = 0;
  int cCount = 0;
  
  ifstream inFile; 
  inFile.open("/usr/share/lib/dict/words");
//  if (!inFile)     // ensure that no error occurred 
  if (inFile.fail())     // ensure that no error occurred 
  {
    cout << "Error opening file - quit\n";  // Ooops - handle error 
    return 1; // exit with error status
  }

        // no error - read every record in file

    cout << "File opened successfully\n";
    cout << "Enter consonants: \n" << endl;
    cin >> numCon; //get number of consonants
	cout << "Enter vowels: \n" << endl;
	cin >> numVow; //get number of vowels
	cout << "Enter first character: \n" << endl;
	cin >> first;
   
	while (inFile >> value) {
      //cout << value << endl;
		if (value.at(0) != first){
			continue;
		}
		for (int i=0; i < value.size(); i++){ ////////////////////////////////////
			if (isalpha(value.at(i))){
				if (value.at(i) == 'A' ||
					value.at(i) == 'a' ||
					value.at(i) == 'E' ||
					value.at(i) == 'e' ||
					value.at(i) == 'I' ||
					value.at(i) == 'i' ||
					value.at(i) == 'O' ||
					value.at(i) == 'o' ||
					value.at(i) == 'U' ||
					value.at(i) == 'u'){
					vCount++;
				} else {
					cCount++;
				}
			}
		}
		if (vCount == numVow && cCount == numCon){ ////////////////////////////
			cout << value <<endl; //Display word
			vCount = 0;
			cCount = 0;
		}
	}
    inFile.close();
	cout << "PROGRAM ENDS: \n" << endl;
  return 0;
}  


Made some modifications and this version compiles. not tested tho ;)
That did it! The program itself has some flaws, but I can debug them much easier now. Thank you very much for the help, everyone. I can see now that I need to be more careful about = and ==, as well as " and '.

If you have any last minute pointers on any other stupid beginners error that I may be overlooking, I'd appreciate it. Thanks again.
Topic archived. No new replies allowed.