Good Morning/Afternoon,
I'm would love some clarification on passing by reference and value. The program being posted works if I set the variable value to "0" but does not override after user input. So I believe the issue is passing, however my professor said everything should be static in this program.
Short: How to pass an input variable without the use of void?
I am very new. This is only chapter 3 so any assistance would be wonderful.
namespace Lesson3
{
class Program
{
public static void Main(string[] args)
{
// declarations
// 12 inches to a foot
// 36 inches to a yard
// 63360 inches per 1 mile
double userInput= 0; // if "0" is removed the program will not function CS0165 error
double feet = 12;
double yards = 36;
double miles = 63360;
double ansFeet = userDivFeet(ref feet, ref userInput);
double ansYards = userDivYards(ref yards, ref userInput);
double ansMiles = userDivMiles(ref miles, ref userInput);
Console.WriteLine("Please enter the number of inches to convert: ");
userInput = Convert.ToInt32(Console.ReadLine());
// output each calculation and display with console to hold the results
WriteLine(userInput + " inches converts into " + ansFeet + " feet.");
WriteLine(userInput + " inches converts into " + ansYards + " yards.");
WriteLine(userInput + " inches converts into " + ansMiles + " miles.");
Console.ReadKey();
}
public static double userDivFeet(ref double userInput, ref double feet)
{
return userInput / feet;
}
public static double userDivYards(ref double userInput, ref double yards)
{
return userInput / yards;
}
public static double userDivMiles(ref double userInput, ref double miles)
{
return userInput / miles;
}
}
}