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

Asked

Viewed 101 times

1

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();

        }
  • 1

    And what’s the mistake?

  • Can post the error, please?

  • when I try to compile the Public void print() { media(); foul(); best(); } my program gets a red mark when missing()

  • Gravity Code Description Project File Line Deletion State Error CS7036 There is no argument provided that corresponds to the required formal parameter "mfinal" of "Note.foul(double)" Consoleapp56 C: Users Matheus source Consoleapp56 Consoleapp56 Note.Cs 59 Active

  • 1

    1- The method public string falta(double mfinal) does not return a string. if nothing returns, then change to void. 2- In the method public void print() the call for the method falta() is not passing the parameter. Anyway... the problem is at the base...!!!

  • "the call for the missing method() is not passing the parameter". ?

Show 1 more comment

2 answers

2


Actually the code has several problems, including conceptual ones, but for a very basic exercise only of mechanisms most are not a big problem. It also has problems of organization and naming names that do not follow the pattern of C#. Do not give error but get used to do better. Note that I simplified the code a long time ago, you don’t have 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, so the code becomes more readable.

One thing I didn’t do was validate the data entry, the correct thing is to validate. For example when converting to number may 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 for a data entry.

I also didn’t care if the class should have one builder, maybe.

I didn’t get the credit either wear a decimal note-only, in many cases no need, but accuracy may be a requirement.

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

Anyway, I solved the problem, but 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();
    }
}

Behold working in the ideone. And in the .NET Fiddle. Also put on the Github for future reference.

0

A simple solution to your problem is to pass a value as parameter when you call the method, and add a return at 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 you, because you have defined in the creation of the method, and for the same reason you need to have a return at the end of the method.

Defining type of return:

public string foul(double mfinal)

Defining parameterization:

public string foul(double mfinal)

I hope I’ve helped, any doubt just comment.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.