C
C#16mo ago
divolo

❔ new to programming and can't figure out

i want to create an appointment scheduler that let's the user create view update and delete but can't figure out how using System; using System.Data; namespace appointment { class Program { static void Main(string[] args) { bool showMenu = true; while (showMenu) { showMenu = Mainmenu(); } } private static bool Mainmenu() { Console.Clear(); Console.WriteLine("menu"); Console.WriteLine("1 )schedule appointment"); Console.WriteLine("2 )view appointment"); Console.WriteLine("3 )update appointment"); Console.WriteLine("4 )delete appointment"); Console.WriteLine("5 )exit"); Console.Write("\r\nselect an option:"); switch (Console.ReadLine()) { case "1": return true; case "2": return true; case "3": return true; case "4": return true; case "5": return false; default: return true; } } private static void } }
27 Replies
Omnissiah
Omnissiah16mo ago
ok, but any more details? where do you want to keep your data?
Pobiega
Pobiega16mo ago
@divolo more details needed. Where are you stuck? What have you tried? How do you want to persist (store) your data?
divolo
divoloOP16mo ago
i don't know how to store data the user inputs nor how to let the user delete any changes they want
Pobiega
Pobiega16mo ago
okay, well, you'll likely want to have a list of appointments in your program, and then save/load that to/from a file on disk as needed step 1 might be to define what an Appointment class looks like
divolo
divoloOP16mo ago
like this? class appointment { public string title; public string date; public string time; public string loation; }
Pobiega
Pobiega16mo ago
Something like that, but those are fields and should probably be properties in an idiomatic C# program
divolo
divoloOP16mo ago
like this public string? Title { get => title; set => title = value; } public string? Date { get => date; set => date = value; } public string? Time { get => time; set => time = value; } public string? Location { get => location; set => location = value; }
SinFluxx
SinFluxx16mo ago
should just be able to do public string? Title { get; set; }
divolo
divoloOP16mo ago
{ internal class Appointment { public string? title; public string? date; public string? time; public string? location; public string Title { get; set; } public string Date { get; set; } public string Time { get; set; } public string? Location { get; set; }
} right?
SinFluxx
SinFluxx16mo ago
don't need all your public string? title;
divolo
divoloOP16mo ago
public string? Title { get; set; } public string? Date { get; set; } public string? Time { get; set; } public string? Location { get; set; } or should i delete the ?
SinFluxx
SinFluxx16mo ago
you can remove it, but you'll then get a compiler warning, this explains it a bit more and what options you have, but don't worry if it's a bit much right now! https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/nullable-warnings#nonnullable-reference-not-initialized
Resolve nullable warnings
Several compiler warnings indicate code that isn't null-safe. Learn how to address those warnings by making your code more resilient.
SinFluxx
SinFluxx16mo ago
if you do remove the ? you'll still be able to carry on with your program without doing anything about it, just that if you then forget to assign a value to one of those properties you'll get an exception
divolo
divoloOP16mo ago
so if i remove it it won't change anything right?
SinFluxx
SinFluxx16mo ago
nothing will "change" exactly, no, you'll see a warning under those lines in visual studio telling you that you haven't given those properties a value but at that point it's just a warning
divolo
divoloOP16mo ago
so i've defined appointment how do i store what the user inputs in the appointment? sorry if my english isn't clear english isn't my first language
SinFluxx
SinFluxx16mo ago
well you'll have to receive, Read, data from the user, make an Appointment from it, and store it in a file/database/whatever you're using
Pobiega
Pobiega16mo ago
I recommend making a public Appointment CreateAppointment() method that you call from your main menu, and add the returned appointment object to your list of appointments you'll need to make that function and that list
divolo
divoloOP16mo ago
namespace appointment_scheduler
{
internal class Appointment
{
public string? title;
public string? date;
public string? time;
public string? location;

public string? Title { get; set; }
public string? Date { get; set; }
public string? Time { get; set; }
public string? Location { get; set; }


}


class program
{

static void Main(string[] args)
{
Appointment appointment = new Appointment();
bool showMenu = true;
while (showMenu)
{
showMenu = Mainmenu();

public Appointment? CreateAppointment();

}

}

private static bool Mainmenu()
{
Console.Clear();
Console.WriteLine("menu");
Console.WriteLine("1 )schedule appointment");
Console.WriteLine("2 )view appointment");
Console.WriteLine("3 )update appointment");
Console.WriteLine("4 )delete appointment");
Console.WriteLine("5 )exit");
Console.Write("\r\nselect an option:");
switch (Console.ReadLine())
{
case "1":

return true;
case "2":

return true;
case "3":

return true;
case "4":

return true;
case "5":

return false;
default:
return true;
}
}
List<Appointment> numbers = new List<Appointment>();


}

the public Appointment CreateAppointment() keeps saying it must be declared
namespace appointment_scheduler
{
internal class Appointment
{
public string? title;
public string? date;
public string? time;
public string? location;

public string? Title { get; set; }
public string? Date { get; set; }
public string? Time { get; set; }
public string? Location { get; set; }


}


class program
{

static void Main(string[] args)
{
Appointment appointment = new Appointment();
bool showMenu = true;
while (showMenu)
{
showMenu = Mainmenu();

public Appointment? CreateAppointment();

}

}

private static bool Mainmenu()
{
Console.Clear();
Console.WriteLine("menu");
Console.WriteLine("1 )schedule appointment");
Console.WriteLine("2 )view appointment");
Console.WriteLine("3 )update appointment");
Console.WriteLine("4 )delete appointment");
Console.WriteLine("5 )exit");
Console.Write("\r\nselect an option:");
switch (Console.ReadLine())
{
case "1":

return true;
case "2":

return true;
case "3":

return true;
case "4":

return true;
case "5":

return false;
default:
return true;
}
}
List<Appointment> numbers = new List<Appointment>();


}

the public Appointment CreateAppointment() keeps saying it must be declared
SinFluxx
SinFluxx16mo ago
well public Appointment CreateAppointment(); is just a method signature, i.e. just the name of the method and what it will return, you haven't created a body for that method
Pobiega
Pobiega16mo ago
also, don't declare methods inside other methods like that and please: $codegif
divolo
divoloOP16mo ago
public Appointment CreateAppointment()
{
Appointment appointment = new Appointment();
}
public Appointment CreateAppointment()
{
Appointment appointment = new Appointment();
}
like this?
Pobiega
Pobiega16mo ago
something like that you should add more code in that block thou, to ask for details and fill the object before returning it
divolo
divoloOP16mo ago
im sorry but can you please tell me the steps i should be taking right now
Pobiega
Pobiega16mo ago
well, it seems to me like you already know how to read and write from/to the console so how about you do that?
Accord
Accord16mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server