我想做一个投票系统,但是不知道怎么计算投票 那位高手可以帮帮我啊总票数 5557 非常好 2000一般   1000很差   2557请问怎么计算我才知道 非常好,一般,很差  的百分比啊

解决方案 »

  1.   

    把数据转换成 float 数据类型,再用/除去一下就可以了。
      

  2.   

    class MainClass
    {
    private static float good=0.8f;//优秀比例
    private  static float bad=0.3f;//差比例
    public static void Main(string[] args)
    {


    int Ticket=5000;//总票数
    Console.WriteLine(TP(3500,Ticket));
    Console.ReadLine();
    }


    private static string TP(float ticket,float TicketCount)
    {
    string RetVal="一般";
    float t=ticket/TicketCount;

    if (t>good)
    RetVal="优秀";
    if (t<bad)
    RetVal="差";

    return RetVal;
    }
    }
      

  3.   

    int verygood;
    int nornal;
    int bad;
    你原来是不是这样写的代码呀?写成这样不就成了?
    double verygood=0;//好
                double nornal = 0;//一般
                double bad = 0;//差
                string 好;
                string 一般;
                string 差;
                double all = 0;//总投票
                all = verygood + nornal + bad;             //这中间是你取3样投票的标数的地方,如果没有代码,会出现0分母错误
                if (all == 0)
                {
                    好 = "0%";
                    一般 = "0%";
                    差 = "0%";
                }
                else
                {
                    double bverygood = verygood / all * 100;
                    double bnornal = nornal / all * 100;
                    double bbad = bad / all * 100;                好 = bverygood.ToString("0.00") + "%";
                    一般 = bnornal.ToString("0.00") + "%";
                    差 = bbad.ToString("0.00") + "%";
                }