码迷,mamicode.com
首页 > 其他好文 > 详细

第四天学习内容 if switch for 的练习

时间:2015-03-03 13:12:54      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
          /*  Console.WriteLine("请输入公里数:");
            double a = Convert.ToDouble(Console.ReadLine());
            double b;
            if (a<=3&&a>0)
            {
                b = 8;
               
            }
            else
            {
                b = 8 + 1.5 * (a-3);
            }
            Console.WriteLine("您应付的车费为:" + b+"元");
            Console.ReadKey();*/

 

            /*企业发放奖金根据利润提成:利润i<=100000元的,奖金可提10%;
             * 100000《i《=200000元是,低于100000的按10%提,高于100000的部分,可提7.5%;
             * 200000《i《=400000元时,低于200000的部分仍按上述办法提成(下同),高于200000的按5%提成;
             * 400000《i《=600000元时,高于400000的部分按3%提成;
             * 600000《i《=1000000元时,高于600000的部分按1.5%提成;
             * i》1000000时,超过1000000的部分按1%提成。
             * 从键盘输入当月利润,求应发奖金
             *
             *
                        Console.WriteLine("请输入当月利润");
                        double i = Convert.ToDouble(Console.ReadLine());
                        int m1 = 100000, m2 = 200000, m3 = 400000, m4 = 600000, m5 = 1000000;
                        double m;
                        if (i>0&&i<=m1)
                        {
                            m = 0.1 * i;                                                  
               
                        }
                        else
                        {
                            if (i>m1&&i<=m2)
                            {
                                m = m1*0.1 + (i - m1) * 0.075;
                            }
                            else
                            {
                                if (i>m2&&i<=m3)
                                {
                                    m = m1 * 0.1 + (m2 - m1) * 0.075 + (i - m2) * 0.05;
                                }
                                else
                                {
                                    if (i>m3&&i<=m4)
                                    {
                                        m = m1 * 0.1 + (m2 - m1) * 0.075 + (m3 - m2) * 0.05 + (i - m3) * 0.03;
                                    }
                                    else
                                    {
                                        if (i>m4&&i<=m5)
                                        {
                                            m = m1 * 0.1 + (m2 - m1) * 0.075 + (m3 - m2) * 0.05 + (m4 - m3) * 0.03 + (i - m4) * 0.015;
                                        }
                                        else
                                        {
                                            m = m1 * 0.1 + (m2 - m1) * 0.075 + (m3 - m2) * 0.05 + (m4 - m3) * 0.03 + (m5 - m4) * 0.015 + (i - m5) * 0.01;
                                        }
                                    }

                                }

                            }

                        }
                        Console.WriteLine("应发奖金数:"+m);
                        Console.ReadKey();

             /* 用switch语句写    if (i >= 1000000)
                        {
                            c = 10;
                        }
                        else
                        {
                            c = i / 100000;
                        }
                        switch (c)
                        {
                            case 0:             m = 0.1 * i;
             *              case 1:             m = m1*0.1 + (i - m1) * 0.075;
                               .
             *                 .
             *                 .
             *               case 10:
                            default:
                                break;


//做一个计算器
            Console.WriteLine("请输入两个数");
           double a=Convert.ToDouble( Console.ReadLine());
           double  b = Convert.ToDouble(Console.ReadLine());
           double c=0;
            Console.WriteLine("请输入一个运算符");
            string x = Console.ReadLine();
            switch (x)
            {
                case ("+"):
                    c = a + b;
                    break;
                case ("-"):
                    c = a - b;
                    break;
                case ("*"):
                    c = a * b;
                    break;
                case ("/"):
                    c = a / b;
                    break;
                case ("%"):
                    c = a % b;
                    break;
                default:
                    Console.WriteLine("输入有误");
                    break;
            }
            Console.WriteLine(a+x+b+"="+c);
            Console.ReadKey();

 

           
     //    打印n个你好
            Console.WriteLine("输入n的值");
            int n = Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                Console.WriteLine("你好");
            }
            Console.ReadKey();


//100以内的奇偶数
            for (int i = 0; i < 100; i++)
            {
                if (i%2==0)
                {
                    Console.WriteLine(i + "是偶数");
                }
                else
                {
                    Console.WriteLine("\t"+i + "是奇数");
                }
            }
            Console.ReadKey();

 

   //打印星星
            Console.WriteLine("输入n的值");
            int n = Convert.ToInt32(Console.ReadLine());
            string x = "";
            string y = "★";
            for (int i = 0; i < n; i++)
            {
                x = x + y;
                Console.WriteLine(x);
            }
            Console.WriteLine("------------------");
            for (int i = n; i>=0 ; i--)
            {
                for (int z = 1; z <=i; z++)
                {
                    Console.Write(y);
                }
                Console.Write("\n");
            }
            Console.ReadKey();   

 

        /

///求和
         Console.WriteLine("输入n的值");
           int n=Convert.ToInt32( Console.ReadLine());
            int sum = 0;
            for (int i = 0; i <=n; i++)
            {
                sum = sum + i;
            }
            Console.WriteLine(sum);
            Console.ReadKey();  

////打印空格加&
            Console.WriteLine("请输入n的值:");
            int n = Convert.ToInt32(Console.ReadLine());
            string x = "";
            string y = "&";
            for (int i = 0; i<=n; i++)
            {
                for (int i1 = 0; i1 <n-i; i1++)
                {
                    Console.Write(" ");
                }
                 x = x + y;
                Console.WriteLine(x);
              
            }
            Console.ReadKey();  */


            Console.WriteLine("输入节数");
            int a = Convert.ToInt32(Console.ReadLine());
            int sum = 0;
            if (a>100)
            {
                Console.WriteLine("你的输入有误");
            }
            else
            {
                for (int i = 1; i <= a; i++)
                {
                    if (i < 50)
                    {
                        sum = sum+i;
                    }
                    else
                    {
                        sum += 10;
                    }
                }
            }
            Console.WriteLine("您得到的分数是" + sum);
            Console.ReadKey();
        }
    }
}

第四天学习内容 if switch for 的练习

标签:

原文地址:http://www.cnblogs.com/William-1234/p/4310581.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!