Trouble finding the errors

can someone help me with what's wrong with this code? I can't seem to get it to work.

The assignment is to write "I will always use object-oriented design" 100 times with a few "accidental" errors, numbering each line.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <cstdlib>
#include <iostream>


const int CAP = 100;
float a[CAP];
enum Error() {4, 8, 15, 16, 23, 42, 65, 88}; //setting up which numbers will produce errors


for (int i = 0; i <= CAP; i++) 
{
if (a[i] > 0; a[i] =! Error) {cout << a[i] << ". I will always use object-oriented design." << '/n'; } //sets all but the errored numbers to produce the correct string.
else if (a[i] = Error 0) {cout << a[i] << ". I will alwaysuse object-oriented design." << '/n'; }
else if (a[i] = Error 1) {cout << a[i] << ". I will always fuse object-oriented design." << '/n'; }
else if (a[i] = Error 2) {cout << a[i] << ". I will always use abstract-oriented design." << '/n'; }
else if (a[i] = Error 3) {cout << a[i] << ". I will allways use object-oriented design." << '/n'; }
else if (a[i] = Error 4) {cout << a[i] << ". I willl always use object-oriented design." << '/n'; }
else if (a[i] = Error 5) {cout << a[i] << ". I will always useo bject-oriented design." << '/n'; }
else if (a[i] = Error 6) {cout << a[i] << ". I will always use object-oriented fesign." << '/n'; }
else if (a[i] = Error 7) {cout << a[i] << ". I will never use object-oriented design." << '/n'; }
else {cout << "Done!"}
return 0
}

Hi jackarmstrong
some errors:
-- wheres the main function?

-- enum
http://www.cplusplus.com/doc/tutorial/other_data_types.html

-- use operator != (not equals)
operator =!(equals not) doesn't exist

-- you are returning 0 from inside your loop.

if you still have problems post your new code with the compiler errors(if any).

Jeff

Last edited on
On the first iteration of your for-loop, you quit the function right away by executing this line:
 
return 0;


The code is not well-structured so there is quite an ambiguity here.
-enum declaration is wrong. It should be:
 
enum Error { //values go here }; 


-The new-line character has the wrong escape character. The escape character in c++ is '\' so the new-line character must be '\n'. This is where the std::endl comes useful. You can simply do:
1
2
3
cout<<"my message"<<endl;
//The above is the same as:
cout<<"my message\n";
Thanks for all the help.

I edited it and attempted to recompile, and now i am only receiving four errors (all about missing an unqualified-id) and one 'warning':

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
#include <cstdlib>
#include <iostream>
using namespace std;

int main()
{
	const int CAP = 100;
	float a[CAP];
//WARNING: UNUSED VARIABLE 'a'
	enum Error {4, 8, 15, 16, 23, 42, 65, 88};
//ERROR: EXPECTED UNQUALIFIED-ID BEFORE NUMERIC CONSTANT
	for (int i = 0, i <= CAP, i++) 
//ERROR: EXPECTED UNQUALIFIED-ID BEFORE 'for'
	{
		if (a[i] > 0; a[i] != Error) {cout << a[i] << ". I will always use object-oriented design." << endl; };
		else if (a[i] = Error 0) {cout << a[i] << ". I will alwaysuse object-oriented design." << endl; };
		else if (a[i] = Error 1) {cout << a[i] << ". I will always fuse object-oriented design." << endl; };
		else if (a[i] = Error 2) {cout << a[i] << ". I will always use abstract-oriented design." << endl; };
		else if (a[i] = Error 3) {cout << a[i] << ". I will allways use object-oriented design." << endl; };
		else if (a[i] = Error 4) {cout << a[i] << ". I willl always use object-oriented design." << endl; };
		else if (a[i] = Error 5) {cout << a[i] << ". I will always useo bject-oriented design." << endl; };
		else if (a[i] = Error 6) {cout << a[i] << ". I will always use object-oriented fesign." << endl; };
		else if (a[i] = Error 7) {cout << a[i] << ". I will never use object-oriented design." << endl; };
		else {cout << "Done!"};
	};
	return 0;
//ERROR: EXPECTED UNQUALIFIED-ID BEFORE 'return'
};
//ERROR: EXPECTED UNQUALIFIED-ID BEFORE '}' TOKEN 


Topic archived. No new replies allowed.