-1

How could I go about creating a program in C++ which would let me input a day which would print a timetable for that day, e.g. Monday = "Mathematics Lecture at 10:00", Tuesday = "Mathematics Tutorial at 12:00 to 14:00". And how could I input a time which would then output the lecture for that day, e.g. if I entered 10:00, it would output "Monday, Mathematics Lecture". I'm still learning the basics so unsure of how to construct it and what to use

itsTed
  • 9
  • 7
  • You may want to use a `struct` that contains a time field and a description field. Maybe expand to starting time, ending time and event description (use `std::string`). – Thomas Matthews Oct 19 '18 at 18:12

2 Answers2

1

Since you are beginner, I’ll tell you what to look into (given your level). To get input from the user, you can use cin. To decide what to output, you can use if, else if, and else statements. A better alternative would be the switch statement. To actually output the response, use cout.

Just do a Google search on these and you should be able to construct your program easily. Of course there are better ways to do this... but for a beginner program that is what you should look into.

Bilal Saleem
  • 633
  • 4
  • 8
0

For your beginner level, you'll probably want to create a series of if/else statements, and have the output be determined by what the user enters. The code for that would look a bit like this:

string day;
cout << "Please enter a day of the week: ";
cin >> day;

if(day == "Monday"){
   //output something
}
else if(day == "Tuesday"){
   //output something different
}
else if(day == "Wednesday")...

...and so on and so forth.

You could also use a switch statement (you can learn more about that here: https://www.geeksforgeeks.org/switch-statement-cc/). A switch statement for this program would look a bit like this:

string day;

switch(day){
case "Monday":
    //output something
    break;
case "Tuesday":
    //output something different
    break;
case "Wednesday":...

...and so on and so forth. At your level, your best bet might just be using if/else statements though. Whichever way you choose to do it, good luck!

EDIT: Typo fixes.

John Cvelth
  • 522
  • 1
  • 6
  • 19
Little Boy Blue
  • 311
  • 4
  • 17
  • Did you know that `switch-case` cannot be used with `std::string`? ([proof](https://stackoverflow.com/questions/650162/why-the-switch-statement-cannot-be-applied-on-strings)). – John Cvelth Oct 19 '18 at 20:35
  • @JohnCvelth I actually was not aware; thanks for pointing that out! – Little Boy Blue Oct 20 '18 at 05:31