
▲ 0 r/csharp
WorkTask constructor causes CS1503 errors in teacher tests
I’m working on a C# assignment (MyPlanner), and my code compiles locally, but the teacher’s tests fail with CS1503 errors.
The errors say things like:
- cannot convert from int to string
- cannot convert from string to DateTime
- cannot convert from string to double
- here i have my worktask file >
​
public WorkTask(string title, string description, DateTime dueDate, double estimatedTime, double timeWorked = 0)
: base(title, description, dueDate)
{
this._estimatedTime = estimatedTime;
this._timeWorked = Math.Min(timeWorked, estimatedTime);
}
planner.cs
private void CreateWorkTask(string title, string description, DateTime dueDate)
{
Console.Write("worked time (hour): ");
string twStr = Console.ReadLine() ?? "0";
Console.Write("Estimated time (hour): ");
string etStr = Console.ReadLine() ?? "0";
if (!double.TryParse(twStr, out double tw) || !double.TryParse(etStr, out double et))
{
Console.WriteLine("not valid timeformat.");
return;
}
this._handler.AddTask(new WorkTask(title, description, dueDate, et, tw));
Console.WriteLine("work assigment created!");
}
private void CreatePrivateTask(string title, string description, DateTime dueDate)
{
Console.Write("Place: ");
string location = Console.ReadLine() ?? "";
this._handler.AddTask(new PrivateTask(title, description, location, dueDate));
Console.WriteLine("personal assigment created!");
}
u/FinalFill847 — 1 day ago