Can someone assist me with this?

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
int count,i;
cout << "\nEnter the month's start day (Sunday is 0, Monday is 1, etc.): ";
cin >> i;

cout << "\nEnter the number of days in the month: ";
int days;
cin >> days;

cout << "\n" << " SUN MON TUE WED THU FRI SAT \n";
cout << " --- --- --- --- --- --- --- \n";

for(int i = 1; i <= days; i++)
for(int days = i; days < 7; days++)
cout << setw(5) << i;
cout << "\n";

return 0;

I'm having trouble getting the underlined portion set up. It's supposed to start on whatever numbered day that is input by the user. Also, no matter how many days in the month I put the program still counts to 31?

Last edited on
after a call to cin >> num; you need at the very least a cin.ignore(); call.

This is because when you put in a number your actually put in for example
is really
When you push enter that puts a new line in the stream.

cin >> num will take the number and leave the \n in the stream
Next time you call cin >> num it opens the stream and sees a '\n' in the stream and continues with invalid input.
Untrue, Eddie.

cin >> variable ;

ignores all leading whitespace by default.

It's when you start mixing formatted and unformatted extractions that headaches arise.
The OPs code has a few problems, but that isn't one of 'em.

OP, you have 5 variables delcared in your code. One of them you never use. 2 of them have the same name as 2 other variables.

The inner for loop updates your outer for loop's counter, which may or may not be what you want. The inner for loop can't ever execute more than once because you set the variable days to the outer loop's counter i. i is always >= 7 after the first iteration of the outer loop.
Topic archived. No new replies allowed.