Загрузка...

Help the fool

Thread in C/C++ created by Delorenzies Oct 9, 2021. 227 views

  1. Delorenzies
    Delorenzies Topic starter Oct 9, 2021 179 Jan 9, 2021
    Как сделать так чтобы по завершению программы она возвращалась обратно? А если еще поможете как сделать так, чтобы по написанию Exit она закрывалась буду вообще благодарен, в моих догадках, что тут как то цикл должен участвовать
    [IMG] [IMG]
     
  2. Danimoon
    Danimoon Oct 9, 2021 21 Aug 28, 2021
    обратно это рекурсия. то есть делаешь функцию и вызваешь её внутри себя
    The post was merged to previous Oct 9, 2021
    оберни в функцию все от Console.Write() вызова до конца блока switch
    The post was merged to previous Oct 9, 2021
    затем перед каждым return добавь вызов этой функции
    The post was merged to previous Oct 9, 2021
    скинь код, сделаю за 2 минуты
    The post was merged to previous Oct 9, 2021
    или ты можешь вызывать Main() перед return
     
    1. View previous comments (6)
    2. Danimoon
      Delorenzies, курсы для программирования бесполезны, я раньше много их проходил (там только синтаксис поймешь, и то поверхностный)
    3. Delorenzies Topic starter
      Danimoon, но всеравно откуда то инфу надо черпать?
    4. Danimoon
      Delorenzies, допустим хочешь изучить C#, ищещь учебник и учишь, главное основы понимать, а не синтаксис
  3. Delorenzies
    Delorenzies Topic starter Oct 9, 2021 179 Jan 9, 2021

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace ConsoleApp2
    {
    class Program
    {
    static void Main(string[] args)
    {
    int main;
    string command;
    string SetName;
    string Password;
    string WriteName;
    string TruePass = "5436";
    string ChangeConsoleColor;
    bool exit = true;



    Console.Write("Введите вашу команду: ");
    command = Console.ReadLine();


    switch (command)
    {
    case "SetName":
    Console.Write("Введите ваше имя: ");
    SetName = Console.ReadLine();
    Console.Write("Имя установленно: " + SetName);
    return;
    case "ChangeConsoleColor":
    Console.WriteLine("Выберите цвет консоли:\nRed\nBlue ");
    ChangeConsoleColor = Console.ReadLine();
    if (ChangeConsoleColor == "Red")
    {
    Console.ForegroundColor = ConsoleColor.Red;
    Console.WriteLine("Цвет консоли был изменен на красный");
    }
    else if (ChangeConsoleColor == "Blue")
    {
    Console.ForegroundColor = ConsoleColor.Blue;
    Console.WriteLine("Цвет консоли был изменен на голубой");
    }
    return;
    case "WriteName":
    Console.Write("Введите ваш пароль");
    Password = Console.ReadLine();
    if (Password == TruePass)
    {
    Console.WriteLine("Добро пожаловать - ");
    }
    else
    {
    Console.WriteLine("Пароль введен не верно.");
    }
    return;








    }



    }
    }
    }

     
  4. Danimoon
    Danimoon Oct 9, 2021 21 Aug 28, 2021
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace ConsoleApp2
    {
    class Program
    {
    static void Main(string[] args)
    {
    int main;
    string command;
    string SetName;
    string Password;
    string WriteName;
    string TruePass = "5436";
    string ChangeConsoleColor;
    bool exit = true;



    Console.Write("Введите вашу команду: ");
    command = Console.ReadLine();


    switch (command)
    {
    case "SetName":
    Console.Write("Введите ваше имя: ");
    SetName = Console.ReadLine();
    Console.Write("Имя установленно: " + SetName);
    Main();
    return;
    case "ChangeConsoleColor":
    Console.WriteLine("Выберите цвет консоли:\nRed\nBlue ");
    ChangeConsoleColor = Console.ReadLine();
    if (ChangeConsoleColor == "Red")
    {
    Console.ForegroundColor = ConsoleColor.Red;
    Console.WriteLine("Цвет консоли был изменен на красный");
    }
    else if (ChangeConsoleColor == "Blue")
    {
    Console.ForegroundColor = ConsoleColor.Blue;
    Console.WriteLine("Цвет консоли был изменен на голубой");
    }
    Main();
    return;
    case "WriteName":
    Console.Write("Введите ваш пароль");
    Password = Console.ReadLine();
    if (Password == TruePass)
    {
    Console.WriteLine("Добро пожаловать - ");
    }
    else
    {
    Console.WriteLine("Пароль введен не верно.");
    }
    Main();
    return;
    case "Exit":
    Console.WriteLine("Досвидание))")
    return;








    }



    }
    }
    }
    The post was merged to previous Oct 9, 2021
    проверь, компилятора для c# у меня нет, в редакторе написал
     
    1. Delorenzies Topic starter
      Danimoon, кстати не работает:bug:
    2. Danimoon
      Delorenzies, не пишу на C#, если надо могу скачать компилятор и разобраться
    3. Danimoon
      Delorenzies, просто прочитай о рекурсивой функции, и создай такую
Top
Loading...