How I call a variable declared in a method

Asked

Viewed 19 times

-2

Hello, First I wanted to make it clear that I’m kind of new at programming okay?. Well my problem is that I need to do a method where I ask the user a name, then confirm the name, if the answer is yes, continue the program, but if not, it repeats the question. But the problem is in the variable name, how do I make this program work? Ps: I am doing this in method format because I will use it several times so so I imagine it will be easier in the future of the code. Ps: there is a commented part in the code so if I need to go back with it I don’t need to write it all over again.

I tried to put the variable name in Class Program, but I don’t even know if it works, I also tried to pass this variable by the parameters n=of the method, but it didn’t work, someone can help me?
`

using System;
using System.Threading;

class Program {
  public static void Main (string[] args) {
    string Nome = " ";
    int Segundos = 0;
    int Minutos = 0;
    int Horas = 0;
    /*bool Passa = false;
    string Confirma;*/
    Confirmação("Qual o nome do evento?",$"O nome do evento é: {Nome} correto?","Okay, então, ");
  }
  public static void Confirmação(string texto, string texto2, string texto3, string nome){
    bool Passa;
    string Confirm;
    string Nome;
    Passa = false;
    while (Passa == false){
      Console.WriteLine(texto);
      Confirm =  Console.ReadLine();
      Console.WriteLine(texto2);
      if (Confirm == "Sim"){
        
        Passa = true;
      }else{

        Console.Write(texto3);
      }
    }
  }
}

`

  • Please clarify your specific problem or provide Additional Details to Highlight Exactly what you need. As it’s Currently Written, it’s hard to Tell Exactly what you’re asking.

No answers

Browser other questions tagged

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