首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

switch case 和 level = Math.Log10(amount);有有关问题

2012-02-03 
switch case 和 level Math.Log10(amount)有问题using Systemusing System.Collections.Genericusing

switch case 和 level = Math.Log10(amount);有问题
using System;
using System.Collections.Generic;
using System.Text;

namespace Test1_19
{
  class Program
  {
  static void Main(string[] args)
  {
  Int32 amount, cost, level;
  Console.WriteLine("请输入购买教科书的数量:\n");
  amount = Int32.Parse(Console.ReadLine());
  cost = amount * 25;
  level = Math.Log10(amount);
  switch(level)
  {
  case (level>1&&level<10):
  cost *=0.9;
  break;
   
  case (level>100&&level<1000):
  cost*=0.85;
  break;
  case (level>1000):
  cost*=0.8;
  break;
  default :cost=cost;
  break;
  }
  Console.WriteLine("费用:\n,{0}",cost);


  }
  }
}


[解决办法]

C# code
            cost  = amount * 25;             level = (int)Math.Log10(amount);             switch(level)             {                 case 0:          // 表示:   1 ≤ amount < 10                    break;                 case 1:          // 表示:  10 ≤ amount < 100                    cost *= 0.9;                     break;                 case 2:          // 表示: 100 ≤ amount < 1000                    cost *= 0.85;                     break;                 default:          // 表示: 其他情形,也就是 amount ≥ 1000 或 amount < 1                    cost *= 0.8;                     break;             } 

热点排行