Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C#

number to quantity

using System;

class Program { static string Ask(string question) { Console.Write(question + " "); return Console.ReadLine(); }

static double Price(int quantity) { return quantity * 2;

}

static void Main()
{
    Console.WriteLine("Welcome to the cat food store!");

    string entry = Ask("How many cans are you ordering?");
    int number = int.Parse(entry);
    double total = Price(number);
    Console.WriteLine($"For {number} cans, your total is: ${total}");
}

}

how are we able to pass the number of cans to ( int quantity) if they have different names

1 Answer

Steven Parker
Steven Parker
229,645 Points

The parameter name represents whatever is passed in to the function when it is called. It's effectively like a variable that is assigned to the passed value.