declaration syntax error

student grades program error

Page 1 of 1

7 Replies - 25993 Views - Last Post: 24 October 2006 - 04:22 AM Rate Topic: -----

#1 sunny123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 19-October 06

declaration syntax error

Posted 21 October 2006 - 02:20 PM

could someone help me fix this error. its and declaration syntax error on this line shown below in bold:
if (average > 50) {

this is a program to calculate student grades.

#include <iostream.h>


//function declarations
void inputNumbers(int&,int&,int&);
int calculateAverage(int,int,int);
void displayAverage(int);

void main()
{//start of function main
int number1, number2, number3, average;
inputNumbers(number1,number2,number3);
average= calculateAverage(number1,number2,number3);
displayAverage (average);
}//end of function main

//definition of function inputNumbers
void inputNumbers(int&number1,int&number2,int&number3)
{//start of function inputNumbers
cout<<"Enter first grade:";
cin>>number1;
//prompt for number 2
cout<<"Enter second grade:";
cin>>number2;
//prompt for number 3
cout<<"Enter third grade:";
cin>>number3;
}//end of function input numbers

//definition of function calculateAverage
int calculateAverage(int number1, int number2, int number3)
{//start of function calculateAverage
int average;
average= number1+number2+number3/3;
return average;
}//end of function calculateAverage

//definition of function displayAverage
void displayAverage(int average)
{//start of function displayAverage
cout<<"The Average of the three grades is "<<average;
}//end of function displayAverage

char assignGrade(int average)
if (average > 50) {
	 cout << "Pass:";
}
else if(average == average) {
	 cout << "Pass:";
}
else {
	 cout << "Fail:";
	 cout << "Fail:";
}


Is This A Good Question/Topic? 0
  • +

Replies To: declaration syntax error

#2 BitByte  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 194
  • Joined: 09-August 06

Re: declaration syntax error

Posted 21 October 2006 - 02:45 PM

You are missing '{' '}' around your assign grade function.

This post has been edited by BitByte: 21 October 2006 - 02:46 PM

Was This Post Helpful? 0
  • +
  • -

#3 NyeNye  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 248
  • Joined: 24-September 06

Re: declaration syntax error

Posted 22 October 2006 - 11:28 PM

when your creating a function try to close or terminate your body jus like what BitByte said....

and try to have a second look of your code...
Was This Post Helpful? 0
  • +
  • -

#4 sunny123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 19-October 06

Re: declaration syntax error

Posted 23 October 2006 - 09:32 AM

View PostBitByte, on 21 Oct, 2006 - 02:45 PM, said:

You are missing '{' '}' around your assign grade function.



i put the { around char assign grade function but it still comes witha error saying declaration terminated incorrectly.
code is shown below
#include <iostream.h>


//function declarations
void inputNumbers(int&,int&,int&);
int calculateAverage(int,int,int);
void displayAverage(int);

void main()
{//start of function main
int number1, number2, number3, average;
inputNumbers(number1,number2,number3);
average= calculateAverage(number1,number2,number3);
displayAverage (average);
}//end of function main

//definition of function inputNumbers
void inputNumbers(int&number1,int&number2,int&number3)
{//start of function inputNumbers
cout<<"Enter first grade:";
cin>>number1;
//prompt for number 2
cout<<"Enter second grade:";
cin>>number2;
//prompt for number 3
cout<<"Enter third grade:";
cin>>number3;
}//end of function input numbers

//definition of function calculateAverage
int calculateAverage(int number1, int number2, int number3)
{//start of function calculateAverage
int average;
average= number1+number2+number3/3;
return average;
}//end of function calculateAverage

//definition of function displayAverage
void displayAverage(int average)
{//start of function displayAverage
cout<<"The Average of the three grades is "<<average;
}//end of function displayAverage

{char assignGrade(int average) }
if (average > 50) {
	  cout << "Pass:";
}
else if(average == average) {
	  cout << "Pass:";
}
else {
	  cout << "Fail:";
	  cout << "Fail:";
}

Was This Post Helpful? 0
  • +
  • -

#5 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 250
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: declaration syntax error

Posted 23 October 2006 - 09:39 AM

This:
{char assignGrade(int average) }
if (average > 50) {
cout << "Pass:";
}
else if(average == average) {
cout << "Pass:";
}
else {
cout << "Fail:";
cout << "Fail:";
}


Needs to be ammended to this:
char assignGrade(int average)
{
if (average > 50) {
cout << "Pass:";
}
else if(average == average) {
cout << "Pass:";
}
else {
cout << "Fail:";
cout << "Fail:";
}
}


The braces need to go around the function, not the function header.

The format is as follows:
type name ( parameter1, parameter2, ...) { statement }



http://www.cplusplus.../functions.html
Was This Post Helpful? 0
  • +
  • -

#6 sunny123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 19-October 06

Re: declaration syntax error

Posted 24 October 2006 - 04:07 AM

The prpogram works without any erorrs but not how it should. it stops after giving the everage of the three numbers when it should give the average and then calculate whether pass or fail and output pass or fail. can someone help me solve this.

the coding is shown below
#include <iostream.h>


//function declarations
void inputNumbers(int&,int&,int&);
int calculateAverage(int,int,int);
void displayAverage(int);

void main()
{//start of function main
int number1, number2, number3, average;
inputNumbers(number1,number2,number3);
average= calculateAverage(number1,number2,number3);
displayAverage (average);
}//end of function main

//definition of function inputNumbers
void inputNumbers(int&number1,int&number2,int&number3)
{//start of function inputNumbers
cout<<"Enter first grade:";
cin>>number1;
//prompt for number 2
cout<<"Enter second grade:";
cin>>number2;
//prompt for number 3
cout<<"Enter third grade:";
cin>>number3;
}//end of function input numbers

//definition of function calculateAverage
int calculateAverage(int number1, int number2, int number3)
{//start of function calculateAverage
int average;
average= number1+number2+number3/3;
return average;
}//end of function calculateAverage

//definition of function displayAverage
void displayAverage(int average)
{//start of function displayAverage
cout<<"The Average of the three grades is "<<average;
}//end of function displayAverage

//assign whether pass or fail

char assignGrade(int average)
{
if (average > 50) {
cout << "Pass:";
}
else if(average == average) {
cout << "Pass:";
}
else {
cout << "Fail:";
cout << "Fail:";
}
}

Was This Post Helpful? 0
  • +
  • -

#7 NyeNye  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 248
  • Joined: 24-September 06

Re: declaration syntax error

Posted 24 October 2006 - 04:16 AM

well define a what score to be categorize pass or fail

then...

insert a function to that or....just insert it to the average


then lets see next
Was This Post Helpful? 0
  • +
  • -

#8 gregoryH  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 60
  • View blog
  • Posts: 656
  • Joined: 04-October 06

Re: declaration syntax error

Posted 24 October 2006 - 04:22 AM

View Postsunny123, on 24 Oct, 2006 - 04:07 AM, said:

The prpogram works without any erorrs but not how it should. it stops after giving the everage of the three numbers when it should give the average and then calculate whether pass or fail and output pass or fail. can someone help me solve this.

the coding is shown below
#include <iostream.h>


//function declarations
void inputNumbers(int&,int&,int&);
int calculateAverage(int,int,int);
void displayAverage(int);

void main()
{//start of function main
int number1, number2, number3, average;
inputNumbers(number1,number2,number3);
average= calculateAverage(number1,number2,number3);
displayAverage (average);
}//end of function main

//definition of function inputNumbers
void inputNumbers(int&number1,int&number2,int&number3)
{//start of function inputNumbers
cout<<"Enter first grade:";
cin>>number1;
//prompt for number 2
cout<<"Enter second grade:";
cin>>number2;
//prompt for number 3
cout<<"Enter third grade:";
cin>>number3;
}//end of function input numbers

//definition of function calculateAverage
int calculateAverage(int number1, int number2, int number3)
{//start of function calculateAverage
int average;
average= number1+number2+number3/3;
return average;
}//end of function calculateAverage

//definition of function displayAverage
void displayAverage(int average)
{//start of function displayAverage
cout<<"The Average of the three grades is "<<average;
}//end of function displayAverage

//assign whether pass or fail

char assignGrade(int average)
{
if (average > 50) {
cout << "Pass:";
}
else if(average == average) {
cout << "Pass:";
}
else {
cout << "Fail:";
cout << "Fail:";
}
}

Sunny,

Please use code tags, make reading a little easier.

void main()
{//start of function main
int number1, number2, number3, average;
inputNumbers(number1,number2,number3);
average= calculateAverage(number1,number2,number3);
displayAverage (average);
}//end of function main



Where in the above does your code go off and do the last computations?

What I mean is - aren't you missing the function calls to Assign the Grade?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1