المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Using Methods within a Switch Case



C# Programming
12-13-2009, 12:15 PM
Hello, everyone! I'm in need of assistance. I have to write a program calculating a user's input in a switch case.. I'm having problem.. Within my switch case, I reference a method to execute if the case statement is true.

A Little about my program:

The user will be given a menu. User will then select the option they desire and the amount they would like... User can keep entering the same option over and over(which I initialize the counter).

Here's a snippet of my code.

This is a Method of the Switch:



//Switch Statement Intialize
static void SwitchIntialize(ref int userResponse)
{
switch (userResponse)
{
case 1:
GetY(out yQ, out yTotal);
break;

case 2:
{
GetZ(out zQ, out zTotal);

}
break;

default:
{
Console.WriteLine("Sorry, You've entered an Invalid Number");
Console.WriteLine("Please try Again!!");
}
break;


}


}



Now, This is my Method


//Calculates
static void GetY(out double yQ, out double yTotal)
{
const double yPrice = 60.5;
Console.WriteLine("How many pounds would you like of Y? ");
yQ = Convert.ToDouble(Console.ReadLine());
yQ += yQ;
yTotal = yQ * yPrice;
}//EOF GetY

//Calculates
static void GetZ(out double zQ, out double zTotal)
{

const double zPrice = 20.39;
Console.WriteLine("How many pounds would you like of Z? ");
zQ = Convert.ToDouble(Console.ReadLine());
zQ += zQ;
zTotal = zQ * zPrice;


}//EOF z




For my final output, I will have to display how many lbs of X,Y, and Z the user purchase and the price of it..

I've also, declare it in my main as,

SwitchIntialize(ref int userChoice)





The Errors, that I've encountered are:

The Name yQ does not exist in the current context.
The name yTotal does not exist in the current context.
The best overloaded method match 'Program.GetY(out double, out double); has some invalid arguments
Argument '1': cannot convert from 'out yQ' to 'out double'
Argument '2': cannot convert from 'out yTotal' to 'out double'




The Name zQ does not exist in the current context.
The name zTotal does not exist in the current context.
The best overloaded method match 'Program.GetZ(out double, out double); has some invalid arguments
Argument '1': cannot convert from 'out zQ' to 'out double'
Argument '2': cannot convert from 'out zTotal' to 'out double'