Syntax Errors URGENT FOR FINALS

Desperately need help with this for finals! Instructor says my code is correct, but I get Syntax Errors. Please help! Also, does anyone know of a "syntax error scrubber program" anywhere like the w3c has for HTML and CSS?
PROGRAM:
//*********************************************************
// K. Tavane Griffith
// COP1000.052
// 04/21/2009
// This is the grade calculator program. The highest of the first two grades
// will be added to the third grade to determine the numeric grade average
// for the course.
//*********************************************************

#include<iostream>//required to perform C++ stream I/O functions
#include<iomanip>//required for paramaterized stream manipulators
#include<string>//required to access string functions

using namespace std;//for accessing C++ Standard Library Members
int main()

{
//define variables
int score1;//stores the value of the first test score
int score2;//stores the value of the second test score
int score3;//stores the value of the third test score
int average = 0;//the numeric grade average for the course
string studentName;//user enters the student's name


cout<<"Welcome to the grade calculator. You will input three test scores.\nThe highest of the first 2 grades and the\nthird grade will be added together\nto determine the numeric grade average for the course\nEach test score has a maximum of 50 points."<<endl;//welcome statement to the user

cout<<"Enter the student's name:";//prompts the user inputs the student name
getline( cin, studentName );
if ( ( studentName.size ()==0 ))
{
cout << "\nError:Enter a name:\n "<<endl;//prompts the user to enter a name if they didn't on the first prompt
cin.clear();//reset the read to good
cin.sync();//clear out the contents of the input buffer
getline ( cin,studentName );//inputs studentName
}

cout<<"Please enter test score 1:";//prompts the user to input the first test score
cin>>score1;//inputs score1

if(!cin || score1<0||score1 >50)//logical operation/calculation

{
if (!cin)
{
cout<<"\nTest scores must be a numeric value between 0 and 50, try again.";//prompts the user to try again
}
else if(score1<0)
{
cout<<"\nTest scores cannot be less than zero or a negative number, please enter your score again.";//prompts the user to try again
}
else
{
cout<<"\nTest scores cannot be greater than 50, please enter your score again.";//prompts the user to try again

}
cin.clear();//reset the read to good
cin.sync();//clear out the contents of the input buffer
cin>>score1;//inputs score1
}

cout<<"\nPlease enter test score 2:";//prompts the user to enter the second test score
cin>>score2;//get second test score
if (!cin || score2<0||score2 >50)//logical operation/calculation
{
if (!cin)
{
cout<<"\nTest scores must be a numeric value between 0 and 50, try again.";//error message to user, prompts user to try again
}
else if (score2<0)
{
cout<<"\nTest scores cannot be less than zero or a negative number,\nplease enter your score again.";//prompts the user to try again

}
else
{
cout<<"\nTest scores cannot be greater than 50,\nplease enter your score again.";//prompts the user to try again

}
cin.clear();//reset the read to good
cin.sync();//clear out the contents of the input buffer
cin>>score2;//inputs score2
}

cout<<"\nPlease enter test score 3:";//prompts the user to enter the third test score
cin>>score3;//get third score

if (!cin || score3<0||score3 >50)//logical operation/calculation
{
if (!cin)
{
cout<<"\nTest scores must be a numeric value between 0 and 50, try again.";//prompts the user to try again
}
else if (score3<0)
{
cout<<"\nTest scores cannot be less than zero or a negative number,\nplease enter your score again.";//prompts the user to try again

}
else
{
cout<<"\nTest scores cannot be greater than 50, please enter your score again.";//prompts the user to try again

}
cin.clear();//reset the read to good
cin.sync();//clear out the contents of the input buffer
cin>>score3;//inputs score3

}

if (score1>score2)//begin logical operation/calculation

average = score1+score3;//gets calculation

else //part 2 of logical calculation/operation

average=score2+score3;//gets calculation


cout<<"\nThe average for the course is = ";<<average;//displays message
cout<<studentName;<<"has earned an"
if (average>=90)//begin logical calculation

cout<<"an A for the course.";//displays result of logical calculation to user

else if (average>=80)//logical calculation

cout<<"a B for the course.";//displays result of logical calculation to user

else if (average>=70)//logical calculation

cout<<" a C for the course.";//displays result of logical calculation to user

else if (average>=60)//logical calculation

cout<<" a D for the course.";<<endl;//displays result of logical calculation to user

else //logical calculation

cout<<" an F for the course.";<<endl;//displays result of logical calculation to user

}
cout<<"\nThank you for using this program.";<<endl;//displays end message to user

return 0; // indicate that program ended successfully

} // end function main

Syntax Errors:
k:\intro2programming\project4\p4ktg\p4ktg.cpp(119) : error C2143: syntax error : missing ';' before '<<'
k:\intro2programming\project4\p4ktg\p4ktg.cpp(120) : error C2143: syntax error : missing ';' before '<<'
k:\intro2programming\project4\p4ktg\p4ktg.cpp(125) : error C2181: illegal else without matching if
k:\intro2programming\project4\p4ktg\p4ktg.cpp(135) : error C2143: syntax error : missing ';' before '<<'
k:\intro2programming\project4\p4ktg\p4ktg.cpp(137) : error C2181: illegal else without matching if
k:\intro2programming\project4\p4ktg\p4ktg.cpp(139) : error C2143: syntax error : missing ';' before '<<'
k:\intro2programming\project4\p4ktg\p4ktg.cpp(142) : error C2143: syntax error : missing ';' before '<<'
k:\intro2programming\project4\p4ktg\p4ktg.cpp(142) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
k:\intro2programming\project4\p4ktg\p4ktg.cpp(142) : error C2059: syntax error : '<<'
k:\intro2programming\project4\p4ktg\p4ktg.cpp(144) : error C2059: syntax error : 'return'
k:\intro2programming\project4\p4ktg\p4ktg.cpp(146) : error C2059: syntax error : '}'
k:\intro2programming\project4\p4ktg\p4ktg.cpp(146) : error C2143: syntax error : missing ';' before '}'
k:\intro2programming\project4\p4ktg\p4ktg.cpp(146) : error C2059: syntax error : '}'
If you are stacking cout << ... you must do it this way:

cout<<"text"<<garbage<<"text"<<endl;

You can't put semicolons in randomly or the compilier won't understand where the "<<" is coming from.
Wow - that helped a lot! Thanks! I now just have one syntax error to get rid of:
New Code:
//*********************************************************
// K. Tavane Griffith
// COP1000.052
// 04/22/2009
// This is the grade calculator program. The highest of the first two grades
// will be added to the third grade to determine the numeric grade average
// for the course.
//*********************************************************

#include<iostream>//required to perform C++ stream I/O functions
#include<iomanip>//required for paramaterized stream manipulators
#include<string>//required to access string functions

using namespace std;//for accessing C++ Standard Library Members
int main()

{
//define variables
int score1;//stores the value of the first test score
int score2;//stores the value of the second test score
int score3;//stores the value of the third test score
int average = 0;//the numeric grade average for the course
string studentName;//user enters the student's name


cout<<"Welcome to the grade calculator. You will input three test scores.\nThe highest of the first 2 grades and the\nthird grade will be added together\nto determine the numeric grade average for the course\nEach test score has a maximum of 50 points."<<endl;//welcome statement to the user

cout<<"Enter the student's name:";//prompts the user inputs the student name
getline( cin, studentName );
if ( ( studentName.size ()==0 ))
{
cout << "\nError:Enter a name:\n "<<endl;//prompts the user to enter a name if they didn't on the first prompt
cin.clear();//reset the read to good
cin.sync();//clear out the contents of the input buffer
getline ( cin,studentName );//inputs studentName
}

cout<<"Please enter test score 1:";//prompts the user to input the first test score
cin>>score1;//inputs score1

if(!cin || score1<0||score1 >50)//logical operation/calculation

{
if (!cin)
{
cout<<"\nTest scores must be a numeric value between 0 and 50, try again.";//prompts the user to try again
}
else if(score1<0)
{
cout<<"\nTest scores cannot be less than zero or a negative number, please enter your score again.";//prompts the user to try again
}
else
{
cout<<"\nTest scores cannot be greater than 50, please enter your score again.";//prompts the user to try again

}
cin.clear();//reset the read to good
cin.sync();//clear out the contents of the input buffer
cin>>score1;//inputs score1
}

cout<<"\nPlease enter test score 2:";//prompts the user to enter the second test score
cin>>score2;//get second test score
if (!cin || score2<0||score2 >50)//logical operation/calculation
{
if (!cin)
{
cout<<"\nTest scores must be a numeric value between 0 and 50, try again.";//error message to user, prompts user to try again
}
else if (score2<0)
{
cout<<"\nTest scores cannot be less than zero or a negative number,\nplease enter your score again.";//prompts the user to try again

}
else
{
cout<<"\nTest scores cannot be greater than 50,\nplease enter your score again.";//prompts the user to try again

}
cin.clear();//reset the read to good
cin.sync();//clear out the contents of the input buffer
cin>>score2;//inputs score2
}

cout<<"\nPlease enter test score 3:";//prompts the user to enter the third test score
cin>>score3;//get third score

if (!cin || score3<0||score3 >50)//logical operation/calculation
{
if (!cin)
{
cout<<"\nTest scores must be a numeric value between 0 and 50, try again.";//prompts the user to try again
}
else if (score3<0)
{
cout<<"\nTest scores cannot be less than zero or a negative number,\nplease enter your score again.";//prompts the user to try again

}
else
{
cout<<"\nTest scores cannot be greater than 50, please enter your score again.";//prompts the user to try again

}
cin.clear();//reset the read to good
cin.sync();//clear out the contents of the input buffer
cin>>score3;//inputs score3

}

if (score1>score2)//begin logical operation/calculation

average = score1+score3;//gets calculation

else //part 2 of logical calculation/operation

average=score2+score3;//gets calculation


cout<<"\nThe average for the course is = "<<average;//displays message
cout<<studentName<<"has earned";
<<if (average>=90)//begin logical calculation

<<"an A for the course."//displays result of logical calculation to user

<<else if (average>=80)//logical calculation

<<"a B for the course."//displays result of logical calculation to user

<<else if (average>=70)//logical calculation

<<" a C for the course."//displays result of logical calculation to user

<<else if (average>=60)//logical calculation

<<" a D for the course."//displays result of logical calculation to user

<<else //logical calculation

<<" an F for the course.";//displays result of logical calculation to user


cout<<"\nThank you for using this program."<<endl;//displays end message to user


return 0; // indicate that program ended successfully

} // end function main
P4ktg.cpp
k:\intro2programming\project4\p4ktg\p4ktg.cpp(121) : error C2143: syntax error : missing ';' before '<<'
Build log was saved at "file://k:\Intro2Programming\Project4\P4ktg\Debug\BuildLog.htm"
P4ktg - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
<<if (average>=90)
What.
//*********************************************************
// K. Tavane Griffith
// COP1000.052
// 04/22/2009
// This is the grade calculator program. The highest of the first two grades
// will be added to the third grade to determine the numeric grade average
// for the course.
//*********************************************************

#include<iostream>//required to perform C++ stream I/O functions
#include<iomanip>//required for paramaterized stream manipulators
#include<string>//required to access string functions

using namespace std;//for accessing C++ Standard Library Members
int main()

{
//define variables
int score1;//stores the value of the first test score
int score2;//stores the value of the second test score
int score3;//stores the value of the third test score
int average = 0;//the numeric grade average for the course
string studentName;//user enters the student's name


cout<<"Welcome to the grade calculator. You will input three test scores.\nThe highest of the first 2 grades and the\nthird grade will be added together\nto determine the numeric grade average for the course\nEach test score has a maximum of 50 points."<<endl;//welcome statement to the user

cout<<"Enter the student's name:";//prompts the user inputs the student name
getline( cin, studentName );
if ( ( studentName.size ()==0 ))
{
cout << "\nError:Enter a name:\n "<<endl;//prompts the user to enter a name if they didn't on the first prompt
cin.clear();//reset the read to good
cin.sync();//clear out the contents of the input buffer
getline ( cin,studentName );//inputs studentName
}

cout<<"Please enter test score 1:";//prompts the user to input the first test score
cin>>score1;//inputs score1

if(!cin || score1<0||score1 >50)//logical operation/calculation

{
if (!cin)
{
cout<<"\nTest scores must be a numeric value between 0 and 50, try again.";//prompts the user to try again
}
else if(score1<0)
{
cout<<"\nTest scores cannot be less than zero or a negative number, please enter your score again.";//prompts the user to try again
}
else
{
cout<<"\nTest scores cannot be greater than 50, please enter your score again.";//prompts the user to try again

}
cin.clear();//reset the read to good
cin.sync();//clear out the contents of the input buffer
cin>>score1;//inputs score1
}

cout<<"\nPlease enter test score 2:";//prompts the user to enter the second test score
cin>>score2;//get second test score
if (!cin || score2<0||score2 >50)//logical operation/calculation
{
if (!cin)
{
cout<<"\nTest scores must be a numeric value between 0 and 50, try again.";//error message to user, prompts user to try again
}
else if (score2<0)
{
cout<<"\nTest scores cannot be less than zero or a negative number,\nplease enter your score again.";//prompts the user to try again

}
else
{
cout<<"\nTest scores cannot be greater than 50,\nplease enter your score again.";//prompts the user to try again

}
cin.clear();//reset the read to good
cin.sync();//clear out the contents of the input buffer
cin>>score2;//inputs score2
}

cout<<"\nPlease enter test score 3:";//prompts the user to enter the third test score
cin>>score3;//get third score

if (!cin || score3<0||score3 >50)//logical operation/calculation
{
if (!cin)
{
cout<<"\nTest scores must be a numeric value between 0 and 50, try again.";//prompts the user to try again
}
else if (score3<0)
{
cout<<"\nTest scores cannot be less than zero or a negative number,\nplease enter your score again.";//prompts the user to try again

}
else
{
cout<<"\nTest scores cannot be greater than 50, please enter your score again.";//prompts the user to try again

}
cin.clear();//reset the read to good
cin.sync();//clear out the contents of the input buffer
cin>>score3;//inputs score3

}

if (score1>score2)//begin logical operation/calculation

average = score1+score3;//gets calculation

else //part 2 of logical calculation/operation

average=score2+score3;//gets calculation


cout<<"\nThe average for the course is = "<<average;//displays message
cout<<studentName<<"has earned";
if (average>=90)//begin logical calculation

<<"an A for the course."//displays result of logical calculation to user

else if (average>=80)//logical calculation

<<"a B for the course."//displays result of logical calculation to user

else if (average>=70)//logical calculation

<<" a C for the course."//displays result of logical calculation to user

else if (average>=60)//logical calculation

<<" a D for the course."//displays result of logical calculation to user

else //logical calculation

<<" an F for the course.";//displays result of logical calculation to user


cout<<"\nThank you for using this program."<<endl;//displays end message to user


return 0; // indicate that program ended successfully

} // end function main
k:\intro2programming\project4\p4ktg\p4ktg.cpp(123) : error C2143: syntax error : missing ';' before '<<'
k:\intro2programming\project4\p4ktg\p4ktg.cpp(123) : warning C4390: ';' : empty controlled statement found; is this the intent?
Build log was saved at "file://k:\Intro2Programming\Project4\P4ktg\Debug\BuildLog.htm"
P4ktg - 1 error(s), 1 warning(s)
Gah. Try actually reading the compiler errors. Here's a hint:


k:\intro2programming\project4\p4ktg\p4ktg.cpp(123) : error C2143: syntax error : missing ';' before '<<'


This tells you that line 123 is the problem. Rather than paste your whole source without any formatting and expect us to sift through all of it to find the problem for you, why not just paste line 123 along with the one or two lines above and below it (or better yet, look specifically at line 123 to see if you can spot the problem for yourself).

:o

whats going on here guys...????
black characters all over...!!!!!
Sorry guys it's my first time posting in this forum. I still can't identify the error no matter how hard I try to manipulate the code:

cout<<"\nThe average for the course is = "<<average;//displays message
cout<<studentName<<"has earned";
if (average>=90)//begin logical calculation

LINE 123-----------> <<"an A for the course."//displays result of logical calculation to user

Error 1 error C2143: syntax error : missing ';' before '<<' e:\intro2programming\project4\p4ktg\p4ktg.cpp 123
Warning 2 warning C4390: ';' : empty controlled statement found; is this the intent? e:\intro2programming\project4\p4ktg\p4ktg.cpp 123

This is my best effort yet. The lack of colors I would imagine is just a copy/paste issue with the forum. I need to turn this in before noon today.....I realize for you guys it's probably an easy fix but I'm a beginner and just can't spot it.
cout<<"an A for the course.";

Did you accurately copy this into the forum, or is your code missing these small but crucial details?



Edit:

Use [code][/code] blocks to insert code examples.

1
2
3
4
5
6
7
#include <iostream>
using namespace std;

int main(){
    cout << "The code is much easier to read!";
    return 0;
}
Last edited on
I'm also very new to c++
so I could be totally wrong here, BUT check your if-else-else if blocks

{ }


-Newbie
Thanks for the command.
cout<<"An A for the course.";
means I would have to add the semi colon to B,C,D & F and I am not getting error messages on those lines. I tried that attempt and it gave me more error messages. Also I did clean up my brackets....
You need a cout every time you want to output something. Simply using the insertion operator will not work. You
also need a semicolon after every line. In short, you do need to add these items to B, C, D, and F.
Last edited on
See earlier post about "stacking cout statements" I will try it your way.
Yay! I got it to build with no errors. However the program stopped after I entered the first test score:
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//*********************************************************
// K. Tavane Griffith
// COP1000.052
// 04/22/2009
// This is the grade calculator program. The highest of the first two grades
// will be added to the third grade to determine the numeric grade average 
// for the course.
//*********************************************************

#include<iostream>//required to perform C++ stream I/O functions
#include<iomanip>//required for paramaterized stream manipulators
#include<string>//required to access string functions

using namespace std;//for accessing C++ Standard Library Members
int main()

{
	//define variables
	int score1;//stores the value of the first test score
	int score2;//stores the value of the second test score
	int score3;//stores the value of the third test score
	int average = 0;//the numeric grade average for the course
	string studentName;//user enters the student's name


	cout<<"Welcome to the grade calculator.  You will input three test scores.\nThe highest of the first 2 grades and the\nthird grade will be added together\nto determine the numeric grade average for the course\nEach test score has a maximum of 50 points."<<endl;//welcome statement to the user

	cout<<"Enter the student's name:";//prompts the user inputs the student name
	getline( cin, studentName );
	if ( ( studentName.size ()==0 ))
{
		cout << "\nError:Enter a name:\n "<<endl;//prompts the user to enter a name if they didn't on the first prompt
	    cin.clear();//reset the read to good
		cin.sync();//clear out the contents of the input buffer
		getline ( cin,studentName );//inputs studentName
}
	
	cout<<"Please enter test score 1:";//prompts the user to input the first test score
	cin>>score1;//inputs score1

	if(!cin || score1<0||score1 >50)//logical operation/calculation	
	
	
		if (!cin)
	{
        cout<<"\nTest scores must be a numeric value between 0 and 50, try again.";//prompts the user to try again
    }

	else if(score1<0)
	 {
        cout<<"\nTest scores cannot be less than zero or a negative number, please enter your score again.";//prompts the user to try again
    }
	else 
	 {
        cout<<"\nTest scores cannot be greater than 50, please enter your score again.";//prompts the user to try again
        
    }
	    cin.clear();//reset the read to good
        cin.sync();//clear out the contents of the input buffer
        cin>>score1;//inputs score1
	
	
	cout<<"\nPlease enter test score 2:";//prompts the user to enter the second test score
	cin>>score2;//get second test score	
	if (!cin || score2<0||score2 >50)//logical operation/calculation
	
		if (!cin)
		{
		cout<<"\nTest scores must be a numeric value between 0 and 50, try again.";//error message to user, prompts user to try again
		}
	else if (score2<0)
	{
		cout<<"\nTest scores cannot be less than zero or a negative number,\nplease enter your score again.";//prompts the user to try again
		
	}
	else
	{
		cout<<"\nTest scores cannot be greater than 50,\nplease enter your score again.";//prompts the user to try again
		
	}
	    cin.clear();//reset the read to good
		cin.sync();//clear out the contents of the input buffer
		cin>>score2;//inputs score2
	
	   
	cout<<"\nPlease enter test score 3:";//prompts the user to enter the third test score
	  cin>>score3;//get third score	
	
	if (!cin || score3<0||score3 >50)//logical operation/calculation		
	
		if (!cin)
		{
		cout<<"\nTest scores must be a numeric value between 0 and 50, try again.";//prompts the user to try again
		}
	else if (score3<0)
	{
		cout<<"\nTest scores cannot be less than zero or a negative number,\nplease enter your score again.";//prompts the user to try again

	}
	else
	{
		cout<<"\nTest scores cannot be greater than 50, please enter your score again.";//prompts the user to try again

	}
		cin.clear();//reset the read to good
		cin.sync();//clear out the contents of the input buffer
		cin>>score3;//inputs score3
	


	if (score1>score2)//begin logical operation/calculation
	
		average = score1+score3;//gets calculation
	
	else //part 2 of logical calculation/operation
	
	    average=score2+score3;//gets calculation
	
		
	cout<<"\nThe average for the course is"<<average;//displays message
	cout<<studentName<<"has earned";
	if (average>=90)//begin logical calculation
	
			cout<<"an A for the course.";//displays result of logical calculation to user
	
	else if (average>=80)//logical calculation 
	
			cout<<"a B for the course.";//displays result of logical calculation to user
		
	else if (average>=70)//logical calculation 
	
			cout<<" a C for the course.";//displays result of logical calculation to user
	
	else if (average>=60)//logical calculation 
	
			cout<<" a D for the course.";//displays result of logical calculation to user
		
	else //logical calculation 
	
			cout<<" an F for the course.";//displays result of logical calculation to user
	

		cout<<"\nThank you for using this program."<<endl;//displays end message to user

	
	return 0; // indicate that program ended successfully

} // end function main   
If it stops near the point where you input score1, take a look at the code in that location. You're missing brackets for the if conditional on line 41 (and probably other locations). Without the brackets, you input score1 on line 39 and again on line 60. It's probably stopping on line 60 and waiting for input, and you weren't expecting that.
Thanks everyone for your help so far I wish I had found this at the beginning of the semester.
Topic archived. No new replies allowed.