Write the following code using c #, Write a method called CalculateTuition(). This methodwill prompt the user for the number of courses that she is currently taking and then calculate and display the tuition cost. (cost = number of course * 569.99). Call the CalculateTuition() method two times from the same Main() methodas in question 1.
时间: 2024-02-13 14:01:38 浏览: 25
Sure, here's an example code for you:
```csharp
using System;
namespace TuitionCalculator
{
class Program
{
static void Main(string[] args)
{
// Call the CalculateTuition() method two times
CalculateTuition();
CalculateTuition();
Console.ReadLine(); // Keep the console window open
}
static void CalculateTuition()
{
Console.Write("Enter the number of courses you are taking: ");
int numCourses = int.Parse(Console.ReadLine());
double cost = numCourses * 569.99;
Console.WriteLine("Your tuition cost is: " + cost.ToString("C2"));
}
}
}
```
In this code, the `CalculateTuition()` method prompts the user for the number of courses and calculates the tuition cost based on the formula given. The `Main()` method simply calls this method twice. Note that `ToString("C2")` is used to format the tuition cost as a currency value.