Write the following program using c #,2. 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-01-31 08:01:59 浏览: 63
SQLPrompt_6.3.0.344(亲测有效-免积分)-SQLServer2014.rar
Sure, here's the C# code for the program you described:
```csharp
using System;
class Program {
static void Main() {
// Call CalculateTuition() twice
CalculateTuition();
CalculateTuition();
}
static void CalculateTuition() {
Console.Write("Enter the number of courses: ");
int numCourses = int.Parse(Console.ReadLine());
decimal tuitionCost = numCourses * 569.99m;
Console.WriteLine($"Tuition cost: ${tuitionCost}");
}
}
```
This program defines a method called `CalculateTuition()` that prompts the user for the number of courses they are taking, calculates the tuition cost based on that number, and then displays the cost to the console. In the `Main()` method, we simply call `CalculateTuition()` twice to demonstrate its functionality. Note that we use a decimal literal (`569.99m`) to ensure that the tuition cost calculation is done with decimal precision.
阅读全文