What reason does the "missing ()" at the end of the program Send me an error in which it is not even possible to compile?

Main

Nota estudante = new Nota();
            estudante.Matricula = Console.ReadLine();
            estudante.Nome = Console.ReadLine();
            estudante.Idade = int.Parse(Console.ReadLine());
            estudante.Prova1 = double.Parse(Console.ReadLine());
            estudante.Prova2 = double.Parse(Console.ReadLine());
            estudante.Trabalho = double.Parse(Console.ReadLine());
            estudante.print();

Class

public string Matricula { get; set; }
        public string Nome { get; set; }
        public int Idade { get; set; }
        public double Prova1 { get; set; }
        public double Prova2 { get; set; }
        public double Trabalho { get; set; }

        public void media()
        {
            double mfinal;
            mfinal = ((Prova1 * 2.5) + (Prova2 * 2.5) + (Trabalho * 1.5)) / 6.5;
            Console.WriteLine("Sua media foi igual a: {0:0.00}", mfinal);
        }
        public string falta(double mfinal)
        {
            double pfinal;
            if (mfinal >= 6.0)
            {
                pfinal = 0;
            }
            else
            {
                pfinal = 6.0 - mfinal;

            }
            Console.WriteLine("Nota para passar: {0:0.00} pontos",pfinal);
            //string txt;
            //txt = "Nota para passar:" + pfinal + " pontos";
            //return txt;
        }
        public void melhor()
        {
            double mnota;
            mnota = Prova1;
            if(Prova2 > mnota)
            {
                mnota = Prova2;
            }
            if(Trabalho > mnota)
            {
                mnota = Trabalho;
            }
            Console.WriteLine("Sua maior nota foi: {0:0.00} pontos", mnota);

        }
        public void print()
        {
            media();
            falta();
            melhor();

        }
Author: Maniero, 2019-05-29

2 answers

Actually the code has several problems, including conceptual ones, but for a very basic exercise only of mechanisms most is not a grid problem. It also has problems organizing and naming names that do not follow the C#standard. It makes no mistake but get used to doing it in a better way. Note that I have greatly simplified the code, it has been a long time since you need to write the code in such a complex way. I could have simplified it more. And I gave more correct names for what the method does, this makes the code more readable.

One thing I did not do was validate the data entry, the correct is to validate. For example when converting to number can give error, should not let this occur, so should use the TryParse() and not the Parse() which should only be used in places where you can ensure that the data is correct, which is not the case with a data entry.

I also didn't worry about whether the class should have a constructor , Maybe.

Also did not enter the merit if you should use a decimal for Grades, in many cases do not need, but accuracy may be a requirement.

The central problem is that you are calling a method that requires a parameter without passing a argument. But there's another misconception there. The right thing is to do this on top of the already existing average and decide whether the person passed or how much lack of grade. At least that's what the code implies it should do.

Anyway, I solved the problem, but it can teach wrong if you think it is good to use in real applications.

using static System.Console;

public class Program {
    public static void Main() {
        var estudante = new Nota {
            Matricula = ReadLine(),
            Idade = int.Parse(ReadLine()),
            Prova1 = double.Parse(ReadLine()),
            Prova2 = double.Parse(ReadLine()),
            Trabalho = double.Parse(ReadLine())
        };
        estudante.MostraDadosDeNota();
    }
}
public class Nota {
    public string Matricula { get; set; }
    public string Nome { get; set; }
    public int Idade { get; set; }
    public double Prova1 { get; set; }
    public double Prova2 { get; set; }
    public double Trabalho { get; set; }
    public double Media { get => (Prova1 * 2.5 + Prova2 * 2.5 + Trabalho * 1.5) / 6.5; }

    public void MostrarMedia() => WriteLine($"Sua media foi igual a: {Media:0.00}");
    public void MostrarNotaFaltante() {
        if (Media >= 6.0) WriteLine("Passou");
        else WriteLine($"Faltou {6.0 - Media:0.00} pontos para passar");
    }
    public void MostrarMelhorNota() {
        double nota = Prova1;
        if (Prova2 > nota) nota = Prova2;
        if (Trabalho > nota) nota = Trabalho;
        WriteLine($"Sua maior nota foi: {nota:0.00} pontos");
    }
    public void MostraDadosDeNota() {
        MostrarMedia();
        MostrarNotaFaltante();
        MostrarMelhorNota();
    }
}

See working on ideone. And no .NET Fiddle. Also I put on GitHub for future reference .

 2
Author: Maniero, 2019-05-30 14:15:57

A simple solution to your problem is to pass a value as a parameter when you call the method, and add a return to the end of the method.

Example:

public string falta(double mfinal)
{
    double pfinal;
    if (mfinal >= 6.0)
    {
         pfinal = 0;
    }
    else
    {
         pfinal = 6.0 - mfinal;
    }
    Console.WriteLine("Nota para passar: {0:0.00} pontos",pfinal);
    string txt;
    txt = "Nota para passar:" + pfinal + " pontos";
    return txt;
}

public void print()
{
    media();
    falta(10);
    melhor();
}

You need to pass a value Double as a parameter when calling it, because you defined it in the creation of the method, and for the same reason you need to have a return at the end of the method.

Defining return type:

Public string missing (double mfinal)

Defining parameterization:

Public string missing(double mfinal)

I hope I helped, any questions just comment.

 0
Author: Caio Henrique Reblin, 2019-05-30 12:03:33