SoFLy 0 Newbie Poster

For an assignment, I am writing a program in c++ that prompts the user for the day of the month, the weekday (numerically), the month, and the year. Then, based on that, I've got to have it output a calendar that is similar to the Unix 'cal' command.

I've got the entire program written (date check, leap year, etc.). The only part I'm stuck on right now is how to actually output the calendar portion formatted. My program also currently outputs the month and year (say I type 12 for month and 1999 for year, it will output "December 1999"). We are supposed to use iomanip.

I know that I'm going to have a static print of something like "S M T W T F S"

After that is where I get stuck. Here are a few questions I'm thinking about that I don't quite understand.

  1. How will I figure out the first day of the month, and then have the program read how many spaces to put before it prints "1"?
  2. How will I know when to print newline (\n)?

Beyond that, once I can figure out those two parts, I believe it's just incrementing a counter until it meets the "daysinmonth" variable (wrote a switch function for that).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.