Hello again :)

I had this project (first block of codes below) and out of this program i have to do the same again but this time using functions.

My problem now is, i made some functions ( i hope these are functions) but on the last part (the one with the if else statements) i receive error messages.

Maybe one of you knows what i did wrong there. (Second block of codes below)

#include <iostream>
#include <string>

using namespace std;

main()

{
	string name, course[10];
	int x, y, n; 
	float grade[10];
	char response;
	
	cout<< "Please enter your name: ";
	cin>> name;
	cout<< "Please enter number of subjects: ";
	cin>> y;
	cout<< "Hello " << name << " you have " << y << " subjects." << endl << endl;
	
	n=1;

   	 for(int a=0; a<y; a++)
{
	cout<< "Please enter your course " << n << ":";
	cin>> course[a];
	cout<< endl;
	cout<< "Please enter your Grade: ";
	cin>> grade[a];
	cout<< endl;
	n++;		
}			
			
	cout<< "Course\tGrade\tEquivalent\tRemarks  " << endl;

		  for(int ctr=0;ctr<y;ctr++)
{
		
		  if (grade[ctr] > 5.0)
			    cout<< course[ctr] << "\t" << grade[ctr] << "\t75%\ - lower \t Failed" << endl;
		
		  else if (grade[ctr] == 3.0)
				cout<< course[ctr] << "\t" << grade[ctr] << "\t75% \t\t passed"<< endl;
		
		  else if (grade[ctr] <=2.75)
				cout<< course[ctr] << "\t" << grade[ctr] << "\t78% \t\t passed"<< endl;

	    	  else if (grade[ctr] =2.5)
				cout<< course[ctr]<< "\t" << grade[ctr] << "\t81% \t\t passed"<< endl;
		
		  else if (grade[ctr] <=2.25)
				cout<< course[ctr]<< "\t" << grade[ctr] << "\t84% \t\t passed"<< endl;
		
		  else if (grade[ctr] <=2.0)
				cout<< course[ctr]<< "\t" << grade[ctr] << "\t87% \t\t passed"<< endl;
		
		  else if (grade[ctr] <=1.75)
				cout<< course[ctr]<< "\t" << grade[ctr] << "\t90% \t\t passed"<< endl;
		
		  else if (grade[ctr] <=1.5)
				cout<< course[ctr]<< "\t" << grade[ctr] << "\t\t 93%\t passed"<< endl;
		
		  else if (grade[ctr] <=1.25)
				cout<< course[ctr]<< "\t" << grade[ctr] << "\t96% \t\t passed"<< endl;
		
		  else if (grade[ctr] ==1.0)
				cout<< course[ctr]<< "\t" <<  grade[ctr] << "\t100% \t\t passed"<< endl;

			else 
			cout<<"invalid input of grade"<< endl;
}	
	cin>> response;

return 0;

}

BLOCK 2

#include <iostream>
#include <string>

using namespace std;


void EnterName ()

{
	cout<< "Enter your name: ";

}

void EnterSubject ()

{
	cout<< "Enter the number of subjects: ";

}

void Greetings (double x, double y)

{
	cout<< "Hello " << x << " you have " << y << " subjects.";

}

void EnterCourse (int n)

{
	cout<< "Please enter your course " << n << ":";

}

void EnterGrade ()

{
	cout<< "Please enter your Grade: ";

}

void Titel ()

{
	cout<< "Course\tGrade\tEquivalent\tRemarks  " << endl;

}

void Evaluation (float grade, string course[10], int ctr)

{
	
		  if (grade[ctr] > 5.0)
			    cout<< course[ctr] << "\t" << grade[ctr] << "\t75%\ - lower \t Failed" << endl;
		
		  else if (grade[ctr] == 3.0)
				cout<< course[ctr] << "\t" << grade[ctr] << "\t75% \t\t passed"<< endl;
		
		  else if (grade[ctr] <=2.75)
				cout<< course[ctr] << "\t" << grade[ctr] << "\t78% \t\t passed"<< endl;

	      else if (grade[ctr] =2.5)
				cout<< course[ctr]<< "\t" << grade[ctr] << "\t81% \t\t passed"<< endl;
		
		  else if (grade[ctr] <=2.25)
				cout<< course[ctr]<< "\t" << grade[ctr] << "\t84% \t\t passed"<< endl;
		
		  else if (grade[ctr] <=2.0)
				cout<< course[ctr]<< "\t" << grade[ctr] << "\t87% \t\t passed"<< endl;
		
		  else if (grade[ctr] <=1.75)
				cout<< course[ctr]<< "\t" << grade[ctr] << "\t90% \t\t passed"<< endl;
		
		  else if (grade[ctr] <=1.5)
					cout<< course[ctr]<< "\t" << grade[ctr] << "\t\t 93%\t passed"<< endl;
		
		  else if (grade[ctr] <=1.25)
				cout<< course[ctr]<< "\t" << grade[ctr] << "\t96% \t\t passed"<< endl;
		
		  else if (grade[ctr] ==1.0)
				cout<< course[ctr]<< "\t" <<  grade[ctr] << "\t100% \t\t passed"<< endl;

			else 
			cout<<"invalid input of grade"<< endl;

}


		main()

{

	string name, course[10];
	int a, b, c, x, y, n; 
	float grade[10];
	char response;

		void EnterName ()

			cin>> name;

		void EnterSubject ()

			cin>> y;

		void Greetings (double b, double c)

	n=1;

   	 for(int a=0; a<y; a++)
{

		void EnterCourse ()

			cin>> course[a];


		void EnterGrade ()

			cin>> grade[a];
			cout<< endl;
		n++;		
}			

		void Titel ()

		  for(int ctr=0;ctr<y;ctr++)
{

		void Evaluation (double x, double y)

}	
	cin>> response;

return 0;

}

Thank you for taking your time for it.

Recommended Answers

All 10 Replies

else if (grade[ctr] =2.5) should be == instead of =
main should be int main
You don't need to put void when you are calling the functions in main
Your functions don' t actually do anything and are serving more as prompts. For instance you could have

int entersubject()
{
        int subj;
         cout<<"Enter # of subjects<<endl;
        cin >> subj;
        return subj;
}

or something to that effect. It adds a little bit of extra code but since the example is meant to be illustrative your instructor may want that.

Once again thank you jonsca :)

Im going to change it now

Thank you thank you very much

Fucntion calls should not be preceded by the return type. So, from line 99 to 131 remove all the return type designations.

Learning when to use semi-colons takes a little practice. You should put a semicolon after the closing parenthesis of function calls unless there is a good reason not to. In main(), there isn't a good reason not to use semicolons after the functon calls, so use them.

Since input of name is a string i have to do it like this right?

string EnterName()

{

		string name[10];

		cout<<"Enter your Name: "<<endl;

		cin >> name;

		return name;

}

Or do i have to do it like this?

void EnterName()

{

		string name[10];

		cout<<"Enter your Name: "<<endl;

		cin >> name;

		return name;

}

In the last function with the if else statements it includes string and integers do i have to declare the function as void or something else?

Since input of name is a string i have to do it like this right?

string EnterName()

{

		string name[10];

		cout<<"Enter your Name: "<<endl;

		cin >> name;

		return name;

}

Or do i have to do it like this?

void EnterName()

{

		string name[10];

		cout<<"Enter your Name: "<<endl;

		cin >> name;

		return name;

}

In the last function with the if else statements it includes string and integers do i have to declare the function as void or something else?

Evaluation is just text output to screen so it can be void (your main program doesn't "need" anything from it).

Hello again...

so far i changed it like this.

#include <iostream>
#include <string>

using namespace std;

	
		string EnterName()

{

		string name[10];

		cout<<"Enter your Name: "<<endl;

		cin>> name;

		return name;

}





		int EnterSubject()

{

		int subj;

		cout<< "Enter number of subjects <<endl;

		cin>> subj;

		return subj;

}

		void Greetings (double x, double y)

{
	    cout<< "Hello " << x << " you have " << y << " subjects.";

}


		string EnterCourse()

{

		string course;

		cout<< "Please enter your course " << n << ":";

		cin>> course;

		return course;

}

		void EnterGrade()

			float grade;

			cout<< "Please enter your Grade: ";

			cin>> grade;

			return grade;

}


	void Titel ()

{
	cout<< "Course\tGrade\tEquivalent\tRemarks  " << endl;

}

	void Evaluation (float grade, string course[10], int ctr)

{
	
		  if (grade[ctr] > 5.0)
			    cout<< course[ctr] << "\t" << grade[ctr] << "\t75%\ - lower \t Failed" << endl;
		
		  else if (grade[ctr] == 3.0)
				cout<< course[ctr] << "\t" << grade[ctr] << "\t75% \t\t passed"<< endl;
		
		  else if (grade[ctr] <=2.75)
				cout<< course[ctr] << "\t" << grade[ctr] << "\t78% \t\t passed"<< endl;

	      else if (grade[ctr] ==2.5)
				cout<< course[ctr]<< "\t" << grade[ctr] << "\t81% \t\t passed"<< endl;
		
		  else if (grade[ctr] <=2.25)
				cout<< course[ctr]<< "\t" << grade[ctr] << "\t84% \t\t passed"<< endl;
		
		  else if (grade[ctr] <=2.0)
				cout<< course[ctr]<< "\t" << grade[ctr] << "\t87% \t\t passed"<< endl;
		
		  else if (grade[ctr] <=1.75)
				cout<< course[ctr]<< "\t" << grade[ctr] << "\t90% \t\t passed"<< endl;
		
		  else if (grade[ctr] <=1.5)
					cout<< course[ctr]<< "\t" << grade[ctr] << "\t\t 93%\t passed"<< endl;
		
		  else if (grade[ctr] <=1.25)
				cout<< course[ctr]<< "\t" << grade[ctr] << "\t96% \t\t passed"<< endl;
		
		  else if (grade[ctr] ==1.0)
				cout<< course[ctr]<< "\t" <<  grade[ctr] << "\t100% \t\t passed"<< endl;

			else 
			cout<<"invalid input of grade"<< endl;

}


	int	main()

{

	string name, course[10];
	int a, b, c, x, y, n; 
	float grade[10];
	char response;

			 EnterName ();

			 EnterSubject ();

			 Greetings (double b, double c);

			 n=1;

   	         for(int a=0; a<y; a++)
{

			 EnterCourse ();

			 EnterGrade ();

		
		     n++;		
}			

			 Titel ()

		     for(int ctr=0;ctr<y;ctr++)
{

			 Evaluation (double x, double y);

}	
			cin>> response;

return 0;

}

but i got 7 error messages and most of it it says missing " ; "
But Where???

uuuuppppssss got this one

cout<< "Enter number of subjects" <<endl;

but still 5 errors i dont understand

Entergrade needs to have a return type other than void.
In name you are trying to assign your string to the string array but you only have one name, so pass it in as a string and not an array of strings.
Look at the signature (the parameters) for Evaluation, they don't match in number or in type to how you have defined it. And why is Greeting taking two doubles? Make sure everything matches and makes sense.

When you are returning values from your functions to main you need to capture them somewhere. E.g., for EnterName you need to have name = EnterName(); in main().

In terms of the compiler errors, they are cryptic but try to read what they are telling you. Fix the first error in the list and go from there, usually more will disappear when you fix one.

Puhhh i give up for today....

Instead of lesser errors by fixing i will get more hihi :P

Anyways thanks a lot to you guys... Even though it doesn´t look like that, but i still learned a lot from you guys today specialy from jonsca.

Thank you see you next time :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.