#include <iostream>
#include <iomanip>
usingnamespace std;
/**********************************************************************
* This function does will first ask the user to put a number
* ask the user
***********************************************************************/
void displayTable(int numDays, int offset);
int getNumDays();
int getOffset();
/**********************************************************************
* Main calls all the functions.
***********************************************************************/
int main()
{
int numDays = (getNumDays()) + 1;
int offset = getOffset();
displayTable(numDays, offset);
cout << "\n";
return 0;
}
/**********************************************************************
* Displays the table.
***********************************************************************/
void displayTable(int numDays, int offset)
{
int dow = 1;
if (offset == 6)
offset = -1;
cout << " Su Mo Tu We Th Fr Sa\n ";
for (int count = 1; count < offset; count++)
cout << " ";
dow++;
for (int days = 1; days < numDays; days++)
{
cout << " ";
if (days < 10) //days are set to only have one space not 2
cout << " ";
cout << days;
if ((offset + days + 1) % 7 == 0)
cout << "\n";
}
return;
}
/**********************************************************************
* Asks the user for the offset
***********************************************************************/
int getOffset()
{
int offset;
cout << "Offset: ";
cin >> offset;
return offset;
}
/**********************************************************************
* Asks the user for the numbers of days to set.
***********************************************************************/
int getNumDays()
{
int numDays;
cout << "Number of days: ";
cin >> numDays;
return numDays;
}
I found several problems in the displayTable function. I'm not sure what the lowest value for offset is supposed to be, but I went with 0 = no shift = 1st on Sunday.
The extra spaces following the \n line 38, the +1 line 49, the offset = -1 line 36 all contributed to the problem.
Here's a version which is working for all offset values of 0-6.
The lines commented out are what you had, so you can see what I changed.
void displayTable(int numDays, int offset)
{
int dow = 1;// what's this for?
// if (offset == 6)
// offset = -1;
// cout << " Su Mo Tu We Th Fr Sa\n ";
cout << " Su Mo Tu We Th Fr Sa\n";
// for (int count = 1; count < offset; count++)
for (int count = 0; count < offset; count++)
cout << " ";
dow++;// not used anywhere
for (int days = 1; days < numDays; days++)
{
cout << " ";
if (days < 10) //days are set to only have one space not 2
cout << " ";
cout << days;
// if ((offset + days + 1) % 7 == 0)
if ((offset + days) % 7 == 0)
cout << "\n";
}
return;
}