So, I am a beginner C# programmer, and I can't get my program to work. I want to be able to use the Main() method's user input, pass it to the PaintJobCalc() to calculate a paint job, and send the calculation back to the main method. I have been playing with it for an hour and I can't get anywhere.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
class PaintingEstimate
{
static void Main()
{
string[] input = {};
Write("\n Type a room length in feet >> ");
input[0] = ReadLine();
Write("\n Type a room width in feet >> ");
input[1] = ReadLine();
PaintJobCalc((string[])input.Clone());
}
public static void PaintJobCalc(string[] args)
{
int inputOne = Convert.ToInt32(input[0]);
int inputTwo = Convert.ToInt32(input[1]);
var wallCount = (inputOne + inputTwo) * 2;
var squareFootage = wallCount * 9;
var endEstimate = squareFootage * 6;
WriteLine("\n Your Paint Job total will be ${0}", endEstimate);
ReadLine();
}
}
You don't need array. your method can take two integer parameters and return integer as result. method signature is very important and it must describe input of the method clearly. don't make things ambiguous using wrong signature.
public static int PaintJobCalc(int length, int width)
{
var wallCount = (length + width) * 2;
var squareFootage = wallCount * 9;
var endEstimate = squareFootage * 6;
return endEstimate;
}
static void Main()
{
Write("\n Type a room length in feet >> ");
int length = Convert.ToInt32(ReadLine());
Write("\n Type a room width in feet >> ");
int width = Convert.ToInt32(ReadLine());
var value = PaintJobCalc(length, width);
WriteLine("\n Your Paint Job total will be ${0}", value);
}