Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace The_Average
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 1; i < 3 ; i++)
            {
                int x,y,z,c;

                Console.Write("the student" + i);
                Console.WriteLine(":");
                for (int j = 1; j < 4; j++)
                {
                    Console.Write("the material of degree" + j);
                    Console.WriteLine(":");
                    Console.ReadLine();
                    Console.WriteLine("The_Average"+result);
                }

            }
            int result = ave(x, y, z ,c);
            Console.WriteLine("the result"+result);
            Console.ReadKey();
        }
        static int ave(int x, int y, int z, int c);
    {
        int result = ((x + y + z + c) / 4);
        return result;
    }
}



}
Posted

You fail to assign the ReadLine values to x,y,z and c. As a result your code never works.

Instead of variables, use an array with count 4.
Assign the values and then calculate average in the end.
 
Share this answer
 
This doesn't even compile. If you look in the error list in Visual Studio you will see many messages. Start and the top and start fixing them.

A couple of clues ... you can't use result before you declare it.

static int ave(int x, int y, int z, int c);

is an empty function because of the semi-colon

And you haven't assigned any values to x, y, z or c
 
Share this answer
 
How is that even compiling, or is it? You are using the "result" variable in your for loop but it is declared after the loop not even in the same scope. Also, you are not assigning your x,y,z,c variables any values when you pass them to the ave() method. Change your code to this:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace The_Average
{
    class Program
    {
        static void Main(string[] args)
        {
             int resultOfMethodave;
             int x,y,z,c;


            for (int i = 1; i < 3 ; i++)
            {
//you will have to determine what the actual values for these variables need to be and when they need to be assigned.
                x = 1;
                y = 2;
                z = 3;
                c = 4;
                 
                Console.Write("the student" + i);
                Console.WriteLine(":");
                for (int j = 1; j < 4; j++)
                {
                    Console.Write("the material of degree" + j);
                    Console.WriteLine(":");
                    Console.ReadLine();
                    Console.WriteLine("The_Average"+result);
                }
 
            }
            resultOfMethodave = ave(x, y, z ,c);
            Console.WriteLine("the result"+result);
            Console.ReadKey();
        }
        static int ave(int x, int y, int z, int c);
    {
        int result = ((x + y + z + c) / 4);
        return result;
    }
}
 
}
 
Share this answer
 
We have seen that you have raised the same question again in this forum but for other reason.

I advice you to read some books or online tutorial on basics of C# programming, What is Windows Forms, What is Console application etc. this will save your time and others.

coming to your code there are few problems
1.the variable X,Y and Z are inside the for loop which means these variable are local inside the { } this open and close braces (i.e the for loop) so this will raise compiler error.
2. the variable result is used inside the for loop which is defined after the loop

so all these shows that you lack of understanding the basics of programming how to define variables. stop writing the coding before it goes worst and do read some books you may find tons of free books and tutorials in google.

Good Luck.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900