// GetData() method accepts order number and quantity // that are used in the Ma
ID: 3545058 • Letter: #
Question
// GetData() method accepts order number and quantity
// that are used in the Main() method
// Price is $3.99 each
using System;
class DebugEight1
{
public static void Main()
{
int orderNum, quantity;
double total;
const double PRICE_EACH = 3.99;
GetData(orderNum, out quantity);
total = quantity * PRICE_EACH;
Console.WriteLine("Order #{0}. Quantity ordered = {1}",
orderNum, quantity);
Console.WriteLine("Total is {0}", total.ToString("C"));
}
public static void GetData(int order, out int amount)
{
String s1, s2;
Console.Write("Enter order number ");
s1 = Console.ReadLine();
order = Convert.ToInt32(s1);
Console.Write("Enter quantity ");
s2 = Console.ReadLine();
amount = Convert.ToInt32(s2);
}
}
Error: Use of unassigned local variable 'orderNum'
Explanation / Answer
// GetData() method accepts order number and quantity
// that are used in the Main() method
// Price is $3.99 each
using System;
class DebugEight1
{
public static void Main()
{
int orderNum=0, quantity=0;
double total;
int[] arr = new int[2];
const double PRICE_EACH = 3.99;
arr = GetData(orderNum, quantity);
total = arr[1] * PRICE_EACH;
Console.WriteLine("Order #{0}. Quantity ordered = {1}",
arr[0], arr[1]);
Console.WriteLine("Total is {0}", total.ToString("C"));
}
public static int[] GetData(int order, int amount)
{
int[] arr = new int[2];
Console.Write("Enter order number ");
order = int.Parse(Console.ReadLine());
Console.Write("Enter quantity ");
amount= int.Parse(Console.ReadLine());
arr[0] = order;
arr[1] = amount;
return arr;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.