Click here to Skip to main content
15,888,000 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
// The private method below is what I am trying to call for
protected void CalculateButton_Click(object sender, EventArgs e)
and I have no idea how to call it correctly so I can calculate the daily cost * number of days.




C#
private Double CalculateCostOfStay(String Place, String Days)
        {
            Double TotalCost;
            Double NumberOfDays;
            NumberOfDays = StringToNumber(Days);
            if (Place == "China")
            { TotalCost = 225 * NumberOfDays; }
            else if (Place == "England")
            { TotalCost = 350 * NumberOfDays; }
            else if (Place == "France")
            { TotalCost = 300 * NumberOfDays; }
            else if (Place == "Germany")
            { TotalCost = 275 * NumberOfDays; }
            else if (Place == "Spain")
            { TotalCost = 250 * NumberOfDays; }
            else
            { TotalCost = 0; }
            return TotalCost;
            
           
        }


What I have tried:

// I thought all I had to do was

CalculateCostOfStay();

// It's giving me an error saying there is no argument and I'm not sure if I need to put parameters into it which I have tried but can not get it to work.
Posted
Updated 23-Mar-17 5:56am
Comments
Karthik_Mahalingam 23-Mar-17 11:52am    
what is place and days?
Member 13079959 23-Mar-17 11:56am    
The place comes out of one listbox with the shown countries and days are from another listbox with set amounts
Karthik_Mahalingam 23-Mar-17 12:01pm    
then pass the listbox values as parameter to the function
Member 13079959 23-Mar-17 12:03pm    
thank you!
Karthik_Mahalingam 23-Mar-17 12:04pm    
welcome

1 solution

Just by looking at the header of the CalculateCostOfStay method, it's expecting you to pass in two parameters, both strings. You're not doing that. You're passing in nothing.

So, where do these two parameter values come from? That's what you need to pass in.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900