我試圖在Visual Studio中創建一個簡單的程序,將各種汽車支付添加到一起,然後計算年度成本和使用方法。在C#中創建方法,語法,括號和傳遞問題
我有一些大括號的問題,如果我正確地傳遞變量。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
double loanPayment = 0;
double insurance = 0;
double gas = 0;
double oil = 0;
double tires = 0;
double maintenance = 0;
double monthlyTotal = 0;
double annualTotal = 0;
Console.WriteLine("Please enter the following expenses on a per month basis");
{
getInput(loanPayment, insurance, gas, oil, tires, maintenance);
calculate(monthlyTotal, annualTotal);
Console.WriteLine("Your monthly total is ${0:F2} and your annual total is ${1:F2}", monthlyTotal, annualTotal);
}
}//endMain
static void getInput(ref double loanPayment, ref double insurance, ref double gas, ref double oil, ref double tires, ref double maintenance, ref double monthlyTotal, ref double annualTotal)
{
Console.WriteLine("How much is the loan payment?");
while (!double.TryParse(Console.ReadLine(), out loanPayment))
Console.WriteLine("Error, enter a number");
Console.WriteLine("How much is the insurance?");
while (!double.TryParse(Console.ReadLine(), out insurance))
Console.WriteLine("Error, enter a number");
Console.WriteLine("How much is the gas?");
while (!double.TryParse(Console.ReadLine(), out gas))
Console.WriteLine("Error, enter a number");
Console.WriteLine("How much is the oil?");
while (!double.TryParse(Console.ReadLine(), out oil))
Console.WriteLine("Error, enter a number");
Console.WriteLine("How much is the tires?");
while (!double.TryParse(Console.ReadLine(), out tires))
Console.WriteLine("Error, enter a number");
Console.WriteLine("How much is the maintenence?");
while (!double.TryParse(Console.ReadLine(), out maintenance))
Console.WriteLine("Error, enter a number");
}//endgetInput
{
static void calculate(ref double loanPayment, ref double insurance, ref double gas, ref double oil, ref double tires, ref double maintenance, ref double monthlyTotal, ref double annualTotal);
monthlyTotal = loanPayment + insurance + gas + oil + tires + maintenance;
annualTotal = monthlyTotal * 12;
}//endCalculate
}
}
無論是誰投票關閉這個真的應該停下來想一想,如果他們是有建設性的。有人在尋求幫助,這就是這個網站的用途。幫助他們。如果你不能花時間幫忙,不要來我們的網站。感謝您的理解。 – Milimetric 2013-02-25 00:57:26