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 09:01:59 浏览: 56
c#编写的一个计算器程序
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.
阅读全文