Ввести с клавиатуры значения - C#

Узнай цену своей работы

Формулировка задачи:

Как сделать в данном примере, чтобы Number и num модно было вводить с клавиатуры несколько раз, пока пользователь не введёт ноль?
Листинг программы
  1. using System;
  2. namespace ProgrammingGuide
  3. {
  4. // Class definition.
  5. public class CustomClass
  6. {
  7. // Class members.
  8. //
  9. // Property.
  10. public int Number { get; set; }
  11. // Method.
  12. public int Multiply(int num)
  13. {
  14. return num * Number;
  15. }
  16. // Instance Constructor.
  17. public CustomClass()
  18. {
  19. Number = 0;
  20. }
  21. }
  22. // Another class definition that contains Main, the program entry point.
  23. class Program
  24. {
  25. static void Main(string[] args)
  26. {
  27. // Create an object of type CustomClass.
  28. CustomClass custClass = new CustomClass();
  29. // Set the value of the public property.
  30. custClass.Number = 27;
  31. // Call the public method.
  32. int result = custClass.Multiply(4);
  33. Console.WriteLine($"The result is {result}.");
  34. }
  35. }
  36. }
  37. // The example displays the following output:
  38. // The result is 108.

Решение задачи: «Ввести с клавиатуры значения»

textual
Листинг программы
  1. static void Main(string[] args)
  2.         {
  3.             // Create an object of type CustomClass.
  4.             CustomClass custClass = new CustomClass();
  5.  
  6.             do
  7.             {
  8.                 Console.Write("Enter a digit: ");
  9.                 custClass.Number = int.Parse(Console.ReadLine());
  10.  
  11.                 int result = custClass.Multiply(4);
  12.                 Console.WriteLine($"The result is {result}.");
  13.             }
  14.             while (custClass.Number != 0);
  15.         }

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

8   голосов , оценка 3.75 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы