我的程序计算错了吗?

时间:2018-02-18 01:00:44

标签: c#

所以在我的C#课程中,我被要求;

  

编写一个程序,计算计算机俱乐部将从他们的燕麦棒销售项目的收益中获得的金额。允许用户输入销售的案件数量和每个酒吧的销售价格。每个案例包含12个栏;每个案例以每个案例5.00美元的价格从当地供应商处购买。俱乐部必须向学生政府协会提供10%的收入。显示用货币格式化的收益。为您的解决方案编写适当的方法

我编写了程序,但我很确定数学不会累加(除非我搞砸了我插入计算器的计算。 这是我的代码。

using System;

namespace GranolaBars
{
    class Granola
    {
        static void Main(string[] args)
        {
            // Give user info on program
            Console.WriteLine("The Computer Club buys the cases at $5.00 a case");
            Console.WriteLine("The studdent government gets 10% of profit");
            Console.WriteLine("Total made from sell is number of cases sold minus 10%");

            // Declare the variables
            int casesSold;
            decimal pricePerBar;
            decimal profit;
            decimal proceeds;
            decimal finalOutCome;

            // Set the variables values
            casesSold = GetCasesSold();
            pricePerBar = GetPricePerCase();
            profit = GetProfit(casesSold, pricePerBar);
            proceeds = GetProceeds(profit);
            finalOutCome = GetFinalOutCome(proceeds, profit);

            // The output from the program 
            Console.WriteLine("The amount cases of sold was: {0} ", casesSold);
            Console.WriteLine("The price per bar was {0:C}: ", pricePerBar);
            Console.WriteLine("The gross profit is: {0:C}: ", profit);
            Console.WriteLine("The student government fees are: {0:C} ", proceeds);
            Console.WriteLine("The income minus the student government fees is: {0:C} ", finalOutCome);

            Console.ReadKey();
    }
    public static int GetCasesSold()
    // Method that gets the total number of cases sold
    {
        int CSold;
        Console.Write("Enter the number of cases sold: ");
        CSold = int.Parse(Console.ReadLine());
        return CSold;
    }
    public static decimal GetPricePerCase()
    // Method that gets the price per case of garnola bars
    {
        decimal PerBar;
        Console.Write("Enter the price per bar: ");
        PerBar = decimal.Parse(Console.ReadLine());
        return PerBar;
    }
    public static decimal GetProfit(int CasesSold, decimal PricePerBar)
    // Method to get the Profit
    {
        decimal PriceofCase = 5.00M;
        decimal Earnings;
        Earnings = ((PricePerBar * 12) - PriceofCase);
        return Earnings;
    }
    public static decimal GetProceeds(decimal Profit)
    // Method to get the Proceeds
    {
        decimal StudentGovFunds = .10M;
        return (Profit * StudentGovFunds);
    }
    public static decimal GetFinalOutCome(decimal Proceeds, decimal Profit)
    // Method to calculate the final total made from selling granola pars
    {
        return (Profit - Proceeds);
    }
}

我的程序是否正确计算,或者我错过了什么能使它正确计算?

1 个答案:

答案 0 :(得分:0)

这似乎是一个问题

我的意思是你需要至少在某个时间点出售多少箱子

 public static decimal GetProfit(int CasesSold, decimal PricePerBar)
 // Method to get the Profit
 {
    return (((PricePerBar * 12) - PriceofCase) * CasesSold); 
 }

输出

The Computer Club buys the cases at $5.00 a case
The studdent government gets 10% of profit
Total made from sell is number of cases sold minus 10%
Enter the number of cases sold: 2
Enter the price per bar: 10
The amount cases of sold was: 2
The price per bar was $10.00:
The gross profit is: $230.00:
The student government fees are: $23.00
The income minus the student government fees is: $207.00