A bunch of compiling errors on my program?

Pages: 12
Hello. I have a basic program I am trying to build that is due tomorrow, which is just a basic employee screening program. Of course, I'm getting a bunch of compiler errors. Here is the code.
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
#define ADULT 18; //Age (Integer)
#define SMWD 1000.0; //Salary (Float) Multiplier w/Degree
#define SMWO 600.0  //Salary (float) Multiplier w/o degree using namespace std;
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
int AGE, DEGS, SLY, REAPP;
system("CLS"); //Clear the Screen
cout << "Applicant Screen Test Program \n\n";
cout << "Welcome! \n";
cout << "What is your age in years?";
cin >> AGE;
cout << "Do you have a college degree (Y/N)?"
cin >> DEGS;
if (AGE>=ADULT);
{
	if (DEGS == 'Y' || 'y'); // Nested If statement
	cout << "Congratulations! You qualify for the job!\n";
	cout << "Your calculated annual salary is: $" << setprecision (2) << fixed << AGE * SMWD <<".";
	cout << "Please fill out an application at the front desk.";

else // Greater than 18 years old, but not a college graduate
	{
		cout << "Congratulations! You qualify for the job!\n";
		cout << "Your calculated annual salary is: $" << setprecision (2) << fixed << AGE * SMWO <<".";
		cout << "Please fill out an application at the front desk.";
	}
else // Under 18 years old, not a college graduate.
{
	cout << "We're sorry, you do not qualify for the job. \n";
	cout << "You must be" << AGE << "or older.\n";
	cout << "Please reapply when you're old enough. \n";
	cout << "Have a good day!"
}	
return (0);
}


and here's all the errors I'm getting, and since I'm new to C++, I'm unsure of what these mean.

cpp: In function 'int main()':
19:1: error: expected ';' before 'cin'
cin >> DEGS;
^

4:17: error: expected ')' before ';' token
#define ADULT 18; //Age (Integer)
^
20:10: note: in expansion of macro 'ADULT'
if (AGE>=ADULT);
^
20:15: error: expected primary-expression before ')' token
if (AGE>=ADULT);
^
20:15: error: expected ';' before ')' token
24:91: error: expected primary-expression before '<<' token
cout << "Your calculated annual salary is: $" << setprecision (2) << fixed << AGE * SMWD <<".";
^
:27:1: error: 'else' without a previous 'if'
else // Greater than 18 years old, but not a college graduate
^
33:1: error: 'else' without a previous 'if'
else // Under 18 years old, not a college graduate.
^
:39:1: error: expected ';' before '}' token
}
^
41:1: error: expected '}' at end of input
}
^


Any help would be great! Thanks so much!
define like this:
const double ADULT = 18;
const double SMWD = 1000.0;
const double SMWO = 600.0;

you have to be careful with ";"
your if-else's have problem. use {} correctly

DEGS should be char, not int
Last edited on
@anup30. Thank you! the const doubles really helped! But there is nothing wrong with DEGS now that I added the const doubles.

That cleared most of my compiler errors, but not quite all of them.

Nesting if-else statements are so confusing. My professor didn't make it very clear, and my book isn't much better.

I moved them around and I'm still getting errors.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
if (AGE>=ADULT);
{
	if (DEGS == 'Y' || 'y'); // Nested If statement
	{
	cout << "Congratulations! You qualify for the job!\n";
	cout << "Your calculated annual salary is: $" << setprecision (2) << fixed << AGE * SMWD <<".";
	cout << "Please fill out an application at the front desk.";
}
else // Greater than 18 years old, but not a college graduate
	{
		cout << "Congratulations! You qualify for the job!\n";
		cout << "Your calculated annual salary is: $" << setprecision (2) << fixed << AGE * SMWO <<".";
		cout << "Please fill out an application at the front desk.";
	}
}
else // Under 18 years old, not a college graduate.
{
	cout << "We're sorry, you do not qualify for the job. \n";
	cout << "You must be" << AGE << "or older.\n";
	cout << "Please reapply when you're old enough. \n";
	cout << "Have a good day!";
}	
return (0);
}


I just don't get it.
Last edited on
when you are using if-else
first write

if
{

}

else
{

}

then write code between, its good trick for beginners to eliminate {} error
I'm still trying to start from scratch with the if and else statements by doing the method that you said, and it's still giving me the same error. I don't know what I'm doing wrong. This is so frustrating!

To me this looks cleaner, and it still is invalid...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
if (AGE>=ADULT);
{
	if (DEGS == 'Y' || 'y'); // Nested If statement
	cout << "Congratulations! You qualify for the job!\n";
	cout << "Your calculated annual salary is: $" << setprecision (2) << fixed << AGE * SMWD <<".";
	cout << "Please fill out an application at the front desk.";

else // Greater than 18 years old, but not a college graduate
	{
		cout << "Congratulations! You qualify for the job!\n";
		cout << "Your calculated annual salary is: $" << setprecision (2) << fixed << AGE * SMWO <<".";
		cout << "Please fill out an application at the front desk.";
	}
else // Under 18 years old, not a college graduate.
{
	cout << "We're sorry, you do not qualify for the job. \n";
	cout << "You must be" << AGE << "or older.\n";
	cout << "Please reapply when you're old enough. \n";
	cout << "Have a good day!";
}	
return (0);
}}
Last edited on
I added comments to the brackets to hopefully clear up some of the confusion you have been having, but I think this is what you want.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
if (AGE >= ADULT)
{								// First bracket of bracket pair A
	if (DEGS == 'Y' || 'y') // Nested If statement
	{							// First bracket of bracket pair B
		cout << "Congratulations! You qualify for the job!\n";
		cout << "Your calculated annual salary is: $" << setprecision(2) << fixed << AGE * SMWD << ".";
		cout << "Please fill out an application at the front desk.";
	}							// Closing bracket of bracket pair B
	else // Greater than 18 years old, but not a college graduate
	{							// First bracket of bracket pair C
		cout << "Congratulations! You qualify for the job!\n";
		cout << "Your calculated annual salary is: $" << setprecision(2) << fixed << AGE * SMWO << ".";
		cout << "Please fill out an application at the front desk.";
	}							// Closing bracket of pair C
}
else // Under 18 years old, not a college graduate.
{								// First bracket of pair D
	cout << "We're sorry, you do not qualify for the job. \n";
	cout << "You must be" << AGE << "or older.\n";
	cout << "Please reapply when you're old enough. \n";
	cout << "Have a good day!";
}								//Closing bracket of pair D
return (0);
}								//Closing bracket if main() 
Last edited on
@MrGoat,
if (AGE>=ADULT);

your if statement stops there at ";" as the OPs.
But there is nothing wrong with DEGS

if the user inputs 89 or 121 for DEGS , the program acts same as for 'y' and 'Y'
so, DEGS have be char variable.
Maybe this will help give a visual understanding? Here is my flowchart of what I am trying to accomplish in this code, to help show where (AGE>=ADULT)...

http://i61.tinypic.com/14dzfkp.png


@anup30. Fixed. Thanks. I was just glad someone had a problem I could help with. =P
I'm just lost when it comes to creating an if/else statement for (AGE>=ADULT). That means if the age is 18 or older, the applicant qualifies for the job and gets his age multiplied by $1000. If the applicant is 18 or older but with no college degree, then the program will multiply the age by $600. If the applicant is less than 18 years old, the program will tell the user that they don't qualify.

This flowchart http://i61.tinypic.com/14dzfkp.png Should help give a visual representation of what I am trying to accomplish in this program.
Last edited on
Okay, I figured out the brackets in the code, sort of. Now the code has no compiler errors,

HOWEVER, the variables are switched up.
If I enter 16, it will congratulate the user and tell them to fill out an application; it should be the other way around. If the user enters anything less than 18, it should tell the user they don't qualify. If I enter 18 or older, it will tell the user they don't qualify.

Now all I need is advice on what to switch up!


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
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
int AGE, DEGS, SLY, REAPP;
const double ADULT = 18;
const double SMWD = 1000.0;
const double SMWO = 600.0;
system("CLS"); //Clear the Screen
cout << "Applicant Screen Test Program \n\n";
cout << "Welcome! \n";
cout << "What is your age in years?";
cin >> AGE;
SLY = AGE * SMWD;
if (AGE >= ADULT)
{
   	cout <<"Do you have a college degree (Y/N)?\n";
  	cin >> DEGS;
}
else if (DEGS == 'Y' || 'y')
{   cout << "Congratulations! You qualify for the job!\n";
	cout << "Your calculated annual salary is: $" << setprecision (2) << fixed << SLY << endl;
	cout << "Please fill out an application at the front desk.";
}
else if (DEGS == 'N' || 'n')
{   cout << "Congratulations! You qualify for the job!\n";
	cout << "Your calculated annual salary is: $" << setprecision (2) << fixed << SLY << endl;
	cout << "Please fill out an application at the front desk.";
}
else (ADULT >= AGE);
{ 	cout << "We're sorry, you do not qualify for the job. \n";
	cout << "You must be" << ADULT << "or older.\n";
	cout << "Please reapply when you're old enough. \n";
	cout << "Have a good day!";
}
return (0);}


Please help me! Thanks!
Last edited on
1
2
3
4
5
6
if (AGE >= ADULT)
{
   	cout <<"Do you have a college degree (Y/N)?\n";
  	cin >> DEGS;
}
else if (DEGS == 'Y' || 'y')


your problem is here. You need to change this "else if" into an "if" statement and then nest in inside the previous if statement. To pseudocode:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
if (AGE >= ADULT)
{
   	cout <<"Do you have a college degree (Y/N)?\n";
  	cin >> DEGS;
if (DEGS == 'Y' || 'y')
{   cout << "Congratulations! You qualify for the job!\n";
	cout << "Your calculated annual salary is: $" << setprecision (2) << fixed << SLY << endl;
	cout << "Please fill out an application at the front desk.";
}
else if (DEGS == 'N' || 'n')
{   cout << "Congratulations! You qualify for the job!\n";
	cout << "Your calculated annual salary is: $" << setprecision (2) << fixed << SLY << endl;
	cout << "Please fill out an application at the front desk.";
}
} //end of if

else if (ADULT >= AGE);
{ 	cout << "We're sorry, you do not qualify for the job. \n";
	cout << "You must be" << ADULT << "or older.\n";
	cout << "Please reapply when you're old enough. \n";
	cout << "Have a good day!";
}


Try that. I don't have a C++ compiler on this computer, so I cant test it. the reason you need to do this is because the "else if" doesn't have any previous "if" statement for it to execute other that one you typed in. You have to nest everything into that "if" so that it will execute them. You also need to change the final "else" statement to an "else if". PM me if you have issues or need help.
Last edited on
Okay, the teacher is giving me extended time, since I'm eligible for it.

I seem to have a nice and clean code going, I'm just one step away, therefore, there is just one problem.

The program isn't calculating and multiplying the applicant's age by $600 if they don't have a college degree. It seems to be ignoring the SMWO constant integer, with a value of $600.

BTW, my professor does not want us to define like this:

const double ADULT = 18;
const double SMWD = 1000.0;
const double SMWO = 600.0;

He'd rather us use #define ADULT 18, since it is a float, or else we'll get points taken off for it.

Here is my code...

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
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
int AGE, DEGS;
#define  ADULT 18  //Age (integer)
#define  SMWD  1000.0  //Salary (float) Multiplier with degree
#define  SMWO  600.0  //Salary (float) Multiplier without degree
system("CLS"); //Clear the Screen
cout << "Applicant Screen Test Program \n\n";
cout << "Welcome! \n\n";
cout << "What is your age in years? ";
cin >> AGE;
if (AGE >= ADULT)
{
   	cout <<"Do you have a college degree (Y/N)? ";
  	cin >> DEGS;
if (DEGS == 'Y' || 'y')
{   cout << "Congratulations! You qualify for the job!\n";
	cout << "Your calculated annual salary is: $" << setprecision (2) << fixed << AGE * SMWD << endl;
	cout << "Please fill out an application at the front desk.";
}
else
{   cout << "Congratulations! You qualify for the job!\n";
	cout << "Your calculated annual salary is: $" << setprecision (2) << fixed << AGE * SMWO << endl;
	cout << "Please fill out an application at the front desk.";
}
}
else
{ 	cout << "We're sorry, you do not qualify for the job. \n";
	cout << "You must be " << ADULT << " or older.\n";
	cout << "Please reapply when you're old enough, in " << ADULT-AGE << endl; cout << "years.\n";
	cout << "Thank you for your interest!";
}
return (0);}


I just need this figured out, and I should be good to go.

Why won't the program multiply $600? The expression/instruction I put in (AGE * SMWO) seems pretty clear?
Last edited on
Line 19 - the condition for the if statement is always true. To evaluate an or expression (||) look at both sides:
- The left is DEGS == 'Y', which makes sense.
- The right sight is 'y', a character with non-zero value. That means that expression is always true.
Thus we have something || true, which is also always true.
@Zhuge

I see, there's the solution. But my professor wants to make sure it calculates right, even with a lowercase 'y'. I just need to make sure that it allows the user to calculate y as being uppercase OR lowercase. If I enter a lowercase y, for yes, it will only multiply the age by $600 instead of a thousand. I will get points off for that too.

What do I do to fix that?
Please, I just need one more bit of understanding, that last step. I need to turn this in today.

I just need to make sure that it allows the user to calculate y as being uppercase OR lowercase. If I enter a lowercase y, for yes, it will only multiply the age by $600 instead of a thousand.

How can I fix this? I've tried everything in my head, and I can't come up with this on my own. As you can tell, this programming class is a big struggle, I'm trying so hard to build my codes from the ground up. I've never been so lost in a class.

I need this one last step, thank you.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
using namespace std;

int main () {
	
	
	cout << "enter 'y' or 'Y' \n";
	char c;
	cin >> c;
	if(c=='y' || c=='Y')
		cout << "you entered 'y' or 'Y' \n";
	else
		cout << "you did not enter 'y' or 'Y' \n ";	


return 0;	
}


EDIT: you didn't listen to what i said about char thing
Last edited on
To point out the change posted by anup, you need to put full expressions on both sides of the || operator.
@anup30

I did listen to you, and it makes sense about the CHAR thing, but I had to step around it because my professor wants us to use a symbolic constant for the Degree Status, hence the name "DEGS".

And when I apply your change to the code, it does the opposite for me. Now the program is calculating $600, but when they input Y or y for the program, it ignores the SMWD value for $1000 and calculates their age only by $600.
Last edited on
Pages: 12