Выдается ошибка the name 'k' does not exist in the current context - C#

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

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

Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace ConsoleApplication1
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. double m,x;
  12. int s = 0, t = 0, p = 10;
  13. Console.Write("m=");
  14. m = Convert.ToDouble(Console.ReadLine());
  15. x = m;
  16. do
  17. {
  18. k = x % 10;
  19. s = p * s + k;
  20. x = x / 10;
  21. }
  22. while (x > 0);
  23. Console.WriteLine (s);
  24.  
  25. }
  26. }
  27. }
выдается ошибка the name 'k' does not exist in the current context В чем дело?

Решение задачи: «Выдается ошибка the name 'k' does not exist in the current context»

textual
Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.            double m,x,k;
  13.            int s = 0, t = 0, p = 10;
  14.            Console.Write("m=");
  15.            m = Convert.ToDouble(Console.ReadLine());
  16.            x = m;//получаешь число
  17.            do
  18.            {
  19.                k = x % 10;
  20.                s = Convert.ToInt32(p * s + k);//Кстати тут должно быть так,потому что ты к типу int прибавляешь тип double.
  21.                x = x / 10;
  22.            }
  23.            while (x > 0);
  24.             Console.WriteLine (s);
  25.         }
  26.     }
  27. }

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


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

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

11   голосов , оценка 3.818 из 5

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

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

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