我的计算显示零?但它说我没有错误。我不做什么? [英] My calculations are displaying zero?? but it says i have no errors.What am i not doing?

查看:94
本文介绍了我的计算显示零?但它说我没有错误。我不做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用System;

使用静态System.Console;
$


命名空间Shippings

{

   课程计划

    {

        static void Main()

        {

            string shippedItems;

           十进制货物充值;

            shippedItems = InputItemsShipped();

            shipCharge = InputShippingCharges();

        }¥b $ b        public static string InputItemsShipped()

        {

           字符串iShipped;

           写("输入购买的商品数量:");

            iShipped = ReadLine();

           返回iShipped;

        }¥b $ b        public static decimal InputShippingCharges()

        {

            int itemsShipped = 0;

           十进制运费= 0m;



            if(itemsShipped == 1)

            {

               运费= 2.99m;

            }


  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;否则if(itemsShipped> 1&& itemsShipped< = 5)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; shipping = Convert.ToDecimal(2.99 +((itemsShipped - 1)* 1.99));

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }


  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;否则if(itemsShipped> 5&& itemsShipped< 15)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; shipping = Convert.ToDecimal(2.99 +(1.99 * 4)+((itemsShipped - 5)* 1.49));

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;否则if(itemsShipped> 15)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; shipping = Convert.ToDecimal(2.99 +(1.99 * 4)+(1.49 * 9)+((itemsShipped - 14)* 0.99));

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }


  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; WriteLine("您运送的{0:f0}总件数将产生运费$ {1:f2}",itemsShipped,shipping);

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ReadKey();



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;退货运费;

  &NBSP; &NBSP; &NBSP; }¥b $ b  &NBSP; }
}

using System;
using static System.Console;

namespace Shippings
{
    class Program
    {
        static void Main()
        {
            string shippedItems;
            decimal shipCharge;
            shippedItems = InputItemsShipped();
            shipCharge = InputShippingCharges();
        }
        public static string InputItemsShipped()
        {
            string iShipped;
            Write("Enter the number of item purchased: ");
            iShipped = ReadLine();
            return iShipped;
        }
        public static decimal InputShippingCharges()
        {
            int itemsShipped = 0;
            decimal shipping = 0m;

            if (itemsShipped == 1)
            {
                shipping = 2.99m;
            }

            else if (itemsShipped > 1 && itemsShipped <= 5)
            {
                shipping = Convert.ToDecimal(2.99 + ((itemsShipped - 1) * 1.99));
            }

            else if (itemsShipped > 5 && itemsShipped < 15)
            {
                shipping = Convert.ToDecimal(2.99 + (1.99 * 4) + ((itemsShipped - 5) * 1.49));
            }
            else if (itemsShipped > 15)
            {
                shipping = Convert.ToDecimal(2.99 + (1.99 * 4) + (1.49 * 9) + ((itemsShipped - 14) * 0.99));
            }

            WriteLine("Your Total items shipped of {0:f0} will incur a shipping charge of ${1:f2}", itemsShipped, shipping);
            ReadKey();

            return shipping;
        }
    }
}

推荐答案

你总是用值计算InputShippingCharges方法中的0。传递正确的值,你从上一个方法作为整数得到该方法作为参数:

you compute always with the value of 0 in the InputShippingCharges Method. Pass the correct value, you get from the previous method as integer to that method as argument:

        static void Main(string[] args)
        {
            string shippedItems;
            decimal shipCharge;
            int items = 0;
            shippedItems = InputItemsShipped();
            if (Int32.TryParse(shippedItems, out items))
                shipCharge = InputShippingCharges(items);
            else
                Console.WriteLine("No numeric input");

            Console.ReadKey();

        }

        public static string InputItemsShipped()
        {
            string iShipped;
            Console.WriteLine("Enter the number of item purchased: ");
            iShipped = Console.ReadLine();
            return iShipped;
        }

        public static decimal InputShippingCharges(int itemsShipped)
        {   
            decimal shipping = 0m;

            if (itemsShipped == 1)
            {
                shipping = 2.99m;
            }

            else if (itemsShipped > 1 && itemsShipped <= 5)
            {
                shipping = Convert.ToDecimal(2.99 + ((itemsShipped - 1) * 1.99));
            }

            else if (itemsShipped > 5 && itemsShipped < 15)
            {
                shipping = Convert.ToDecimal(2.99 + (1.99 * 4) + ((itemsShipped - 5) * 1.49));
            }
            else if (itemsShipped > 15)
            {
                shipping = Convert.ToDecimal(2.99 + (1.99 * 4) + (1.49 * 9) + ((itemsShipped - 14) * 0.99));
            }

            Console.WriteLine("Your Total items shipped of {0:f0} will incur a shipping charge of


{1:f2 }",itemsShipped,shipping);

退货运费;
}
{1:f2}", itemsShipped, shipping); return shipping; }

问候,

  Thorsten

  Thorsten


这篇关于我的计算显示零?但它说我没有错误。我不做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆