Visual Studioで簡単なプログラムを作成して、さまざまな車の支払いを合計し、年間コストを計算して方法を使用しようとしています。
中かっこに問題があり、変数を適切に渡しているかどうか。
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
}
}