Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 1-Feb-13 8:07am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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;
    }
}
 
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 509
1 Nirav Prabtani 338
2 OriginalGriff 215
3 _Amy 165
4 Abhinav S 160
0 OriginalGriff 7,715
1 Sergey Alexandrovich Kryukov 6,911
2 Maciej Los 3,954
3 Peter Leow 3,698
4 CHill60 2,742


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 1 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100