4 Replies - 1030 Views - Last Post: 28 February 2012 - 07:14 PM Rate Topic: -----

#1 Eluc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-February 12

No overload for method 'FindAverage' takes '2' argumen

Posted 28 February 2012 - 05:59 PM

Hi
Pretty new to C#.
I want to put certain functions into a method to be able to call them when needed (i.e. InputLine, InputInt, InputDouble). However, when I tried to set it up within FindAverage() It runs through the function but is not what I want. There are variables that have been inputed by a user and I want to be able to use those inputs to get the average. However, I'm not sure where to go about to do this. Any help would be greatly appreciated.
Line 102 - 163 is what I want to be able to have a general function to use in FindAverage. I've tried to use

static double FindAverage (string prompt, int i)
{
double Average = 0;
double Grade = 0;
double Grades = 0;
double Sum = 0;

int NoOfItems = InputInt (prompt, i);
for (i = 0; i<= NoOfItems; i = i +1) 
{

Grade = InputDouble ("Enter grade",0);
Grades = 0;
Sum = Grade + Grades;
Average = Sum / NoOfItems;
}
return Average;
}


but it didn't work out too well.



The code below is my code which runs perfectly fine with the intended output as well.
 using System;

namespace GradeCalc2
{
	class Grades
	{

		static string InputLine (string prompt, int i)
		{
			Console.Write (prompt, i);
			return Console.ReadLine ();
		}

		static int InputInt (string prompt, int i)
		{
			string nStr = InputLine (prompt, i).Trim ();
			return int.Parse (nStr);
		}

		static double InputDouble (string prompt, int i)
		{
			string nStr = InputLine (prompt, i).Trim ();
			return double.Parse (nStr);
		}

		static double FindAverage (double Exam, double Lab, double Hw, double Project, double Participation)
		{
			double number = 0;
			double Average;
			double Sum;
			double grade;
			double grades = 0;		
	
			{

				grade = 0;
				Sum = grade + grades;
				Average = Sum / number;
				
				return Average;
			}
		}

		static void Main ()
		{
			int ExamWeight = 0;
			int LabWeight = 0;
			int HwWeight = 0;
			int ProjectWeight = 0;
			int ParticipationWeight = 0;

			do {
				ExamWeight = InputInt ("Enter the weight for exams: ", ExamWeight);
				Console.WriteLine ("You entered {0} for exams.", ExamWeight);

				LabWeight = InputInt ("Enter the weight for labs: ", LabWeight);
				Console.WriteLine ("You entered {0} for lab.", LabWeight);     

				HwWeight = InputInt ("Enter the weight for homework: ", HwWeight);
				Console.WriteLine ("You entered {0} for homework.", HwWeight);
                
				ProjectWeight = InputInt ("Enter the weight for projects: ", HwWeight);
				Console.WriteLine ("You entered {0} for Projects.", ProjectWeight);
                
				ParticipationWeight = InputInt ("Enter the weight for participation: ", ParticipationWeight);
				Console.WriteLine ("You entered {0} for participation.", ParticipationWeight);

			} while (ExamWeight + LabWeight + HwWeight + ProjectWeight + ParticipationWeight !=100);
        
			double Grade = 0; 

			int ExamNumber = 0;
			int LabNumber = 0;
			int HwNumber = 0;
			int ProjectNumber = 0;
			int ParticipationNumber = 0; 
			
			int ExamSum = 0;
			int LabSum = 0;
			int HwSum = 0;
			int ProjectSum = 0;
			int ParticipationSum = 0;
			int i;
			
			double ExamAverage = 0;
			double LabAverage = 0;
			double HwAverage = 0;
			double ProjectAverage = 0;
			double ParticipationAverage = 0;
			
			double ExamGrade = 0;
			double LabGrade = 0;
			double HwGrade = 0;
			double ProjectGrade = 0;
			double ParticipationGrade = 0;
			{
		
				{
				
					
					{
						ExamNumber = InputInt ("Please enter the number of exams taken.", ExamNumber);
						Console.WriteLine ("You entered {0} for the number of exams taken.", ExamNumber);
					
						LabNumber = InputInt ("Please enter the number of labs done.", LabNumber);
						Console.WriteLine ("You entered {0} for the number of labs done.", LabNumber);

						HwNumber = InputInt ("Please enter the number of homework done.", HwNumber);
						Console.WriteLine ("You entered {0} for the number of homework done.", HwNumber);

						ProjectNumber = InputInt ("Please enter the number of projects done.", ProjectNumber);
						Console.WriteLine ("You entered {0} for the number of projects done.", ProjectNumber);

						ParticipationNumber = InputInt ("Please enter the number of times you have participated.", ParticipationNumber);
						Console.WriteLine ("You entered {0} for the number of times participated done.", ParticipationNumber);	
						
					
						for (i = 1; i <= ExamNumber; i = i +1) {
							ExamSum = InputInt ("Please enter your grade for exam {0}: ", i) + ExamSum;
							Console.WriteLine ("Total exam points: {0}", ExamSum);
						}
				
						ExamAverage = ExamSum / ExamNumber;
						ExamGrade = ExamAverage;

						Console.WriteLine ("Average Exam Grade: {0}", ExamGrade); 
				
					
						for (i = 1; i <= LabNumber; i = i +1) {
							LabSum = InputInt ("Please enter your grade for lab {0}: ", i) + LabSum;
							Console.WriteLine ("Total lab points: {0}", LabSum);
						}
						LabAverage = LabSum / LabNumber;
						LabGrade = LabAverage;
						Console.WriteLine ("Average Lab Grade: {0}", LabGrade); 
				
					
						for (i = 1; i <= HwNumber; i = i +1) {
							HwSum = InputInt ("Please enter your grade for homework {0}: ", i) + HwSum;
							Console.WriteLine ("Total homework points: {0}", HwSum);
						}
				
						HwAverage = HwSum / HwNumber;
						HwGrade = HwAverage;
						Console.WriteLine ("Average Homework Grade: {0}", HwGrade);
				
						
						for (i = 1; i <= ProjectNumber; i = i +1) {
							ProjectSum = InputInt ("Please enter your grade for project {0}: ", i) + ProjectSum;
							Console.WriteLine ("Total project points: {0}", ProjectSum);
						}
						ProjectAverage = ProjectSum / ProjectNumber;
						ProjectGrade = ProjectAverage;
						Console.WriteLine ("Average Project Grade: {0}", ProjectGrade);
				
						
						for (i = 1; i <= ParticipationNumber; i = i +1) {
							ParticipationSum = InputInt ("Please enter your grade for participation {0}: ", i) + ParticipationSum;
							Console.WriteLine ("Total participation points: {0}", ParticipationSum);
						}
						ParticipationAverage = ParticipationSum / ParticipationNumber;
						ParticipationGrade = ParticipationAverage;
						Console.WriteLine ("Average Participation Grade: {0}", ParticipationGrade);
					
				
					
					}
     
					Grade = (ExamGrade * ExamWeight + LabGrade * LabWeight + HwGrade * HwWeight + ProjectGrade * ProjectWeight + ParticipationGrade * ParticipationWeight) / 100;
					
					{
						Console.WriteLine ("Your grade is {0}%", Grade);


						if (Grade >= 93.0)

							Console.WriteLine ("Your grade is higher than a 93% therefore you are getting an A");
						else if ((Grade > 90.0) && (Grade < 93.0))

							Console.WriteLine ("Your grade is greater than a 90% and less than a 93% therefore you are getting an A-");
						else if ((Grade > 87.0) && (Grade < 90.0))

							Console.WriteLine ("Your grade is greater than a 87% and less than a 90% therefore you are getting an B+");
						else if ((Grade > 83.0) && (Grade < 87.0))

							Console.WriteLine ("Your grade is greater than a 83% and less than a 87% therefore you are getting an B");
						else if ((Grade > 80.0) && (Grade < 83.0))

							Console.WriteLine ("Your grade is greater than a 80% and less than a 83% therefore you are getting an B-");
						else if ((Grade > 77.0) && (Grade < 80.0))
                
							Console.WriteLine ("Your grade is greater than a 77% and less than a 80% therefore you are getting an C+");
						else if ((Grade > 73.0) && (Grade < 77.0))

							Console.WriteLine ("Your grade is greater than a 73% and less than a 77% therefore you are getting an C");
						else if ((Grade > 70.0) && (Grade < 73.0))

							Console.WriteLine ("Your grade is greater than a 70% and less than a 73% therefore you are getting an C-");
						else if ((Grade > 67.0) && (Grade < 70.0))

							Console.WriteLine ("Your grade is greater than a 67% and less than a 70% therefore you are getting an D+");
						else if ((Grade > 60.0) && (Grade < 67.0))

							Console.WriteLine ("Your grade is greater than a 60% and less than a 67% therefore you are getting an D");
						else if (Grade < 60.0)  
							Console.WriteLine ("Your grade is lower than a 60% therefore you are getting an F"); 
					}
				}
			}
		}
	}
}



Sorry about the title. I had that problem earlier but was able to fix it and I prematurely posted this thread without updating the title.

Is This A Good Question/Topic? 0
  • +

Replies To: No overload for method 'FindAverage' takes '2' argumen

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2262
  • View blog
  • Posts: 9,466
  • Joined: 29-May 08

Re: No overload for method 'FindAverage' takes '2' argumen

Posted 28 February 2012 - 06:03 PM

What information is the error message telling you?

No overload for method 'FindAverage' takes '2' arguments

No Overload
Method (named FindAverage)
2 Arguments

So ask yourself the following questions
What is a method?
What is a argument?
What is an Overload?

Then ask yourself the question I started with.
Was This Post Helpful? 0
  • +
  • -

#3 superkb10  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 298
  • Joined: 27-November 11

Re: No overload for method 'FindAverage' takes '2' argumen

Posted 28 February 2012 - 06:07 PM

In the future could you please only put in code that is relevant to your question? I really don't think you need to put in 200 lines of code. Anyway, what exactly is your problem? How are you trying to call the method? Also, just one thing about you function,

Grades = 0;
Sum = Grade + Grades;



These two lines basically cancel each other out. What you're basically saying is Sum = Grade Because if Grades is 0, adding 0 to a number, will not change the number.
Was This Post Helpful? 0
  • +
  • -

#4 Eluc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-February 12

Re: No overload for method 'FindAverage' takes '2' argumen

Posted 28 February 2012 - 06:19 PM

Sorry. I'm trying to condense Lines 102 -163 into FindAverage (). I've tried to use a for loop and prompt the user for how many items are in a certain category and then prompting the user for what grade they got in that certain category while adding them on the go and then finally calculating an average grade for that category. I tried to put what was needed into FindAverage() but I'm not sure how to use it for every category since I'm not sure how to store the user input to use later on for the if statement.

To sum it up: I need a function that will be used for different categories but I'm not exactly sure how to go about it.
Was This Post Helpful? 0
  • +
  • -

#5 Eluc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 28-February 12

Re: No overload for method 'FindAverage' takes '2' argumen

Posted 28 February 2012 - 07:14 PM

I was able to solve the problem. thank you for taking the time to reply.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1