How do I get this code to work in a way that looks like a calendar. I have tried but it doesnt look right. The first week is always off i need help plz.
It displays moving the program to the right too much. When offset is put.
It has the appearance of a calendar and just has one tiny error
#include <iostream>
#include <iomanip>
usingnamespace std;
void displayTable(int numDays, int offset);
int getNumDays();
int getOffset();
/**********************************************************************
* MAIN
* Pretty much a delegator. Calls other functions.
***********************************************************************/
int main()
{
int numDays = getNumDays();
int offset = getOffset();
displayTable(numDays, offset);
cout <<"\n";
return 0;
}
/**********************************************************************
* DISPLAYTABLE
* Displays the physical table to the screen.
***********************************************************************/
void displayTable(int numDays, int offset)
{
int days;
int offsetCalc;
offsetCalc = (7 - offset);
cout << " Su Mo Tu We Th Fr Sa\n";
if (offset == 0)
cout << setw(4) << " ";
if (offset == 1)
cout << setw(8) << " ";
if (offset == 2)
cout << setw(12) << " ";
if (offset == 3)
cout << setw(16) << " ";
if (offset == 4)
cout << setw(20) << " ";
if (offset == 5)
cout << setw(24) << " ";
else (offset == 6) ;
if (offsetCalc == 7)
cout << "\n";
for (days = 1; days <= numDays; days++)
{
cout << " " << setw(2) << days;
if (days % 7 == 0)
cout << "\n";
}
return;
}
/**********************************************************************
* OFFSET
* Determines the number of days to offset the Calendar and then returns
* that value back to displayTable.
***********************************************************************/
int getOffset()
{
int offset;
cout << "Offset: ";
cin >> offset;
return offset;
}
/**********************************************************************
* NUMDAYS
* Accepts the number of days from the user.
***********************************************************************/
int getNumDays()
{
int numDays;
cout << "Number of days: ";
cin >> numDays;
return numDays;
}
#include <iostream>
#include <iomanip>
usingnamespace std;
void displayTable(int numDays, int offset);
int getNumDays();
int getOffset();
/**********************************************************************
* MAIN
* Pretty much a delegator. Calls other functions.
***********************************************************************/
int main()
{
int numDays = getNumDays();
int offset = getOffset();
displayTable(numDays, offset);
cout << "\n";
return 0;
}
/**********************************************************************
* DISPLAYTABLE
* Displays the physical table to the screen.
***********************************************************************/
void displayTable(int numDays, int offset)
{
int days;
int offsetCalc;
offsetCalc = (7 - offset);
// Using a for loop instead of all the if statements
cout << " Su Mo Tu We Th Fr Sa\n";
for (int y = 0; y < offset; y++)
cout << " ";
/*if (offset == 0)
cout << setw(4) << " ";
if (offset == 1)
cout << setw(8) << " ";
if (offset == 2)
cout << setw(12) << " ";
if (offset == 3)
cout << setw(16) << " ";
if (offset == 4)
cout << setw(20) << " ";
if (offset == 5)
cout << setw(24) << " ";
else (offset == 6);
if (offsetCalc == 7)
cout << "\n";
*/
for (days = 0; days < numDays; days++)
{
cout << " ";
if (days + 1 < 10)
cout << " "; // To keep numbers less than 10, aligned
cout << days + 1;
if ((offset+days+1) % 7 == 0)// Have to add in the offset
cout << "\n";
}
return;
}
/**********************************************************************
* OFFSET
* Determines the number of days to offset the Calendar and then returns
* that value back to displayTable.
***********************************************************************/
int getOffset()
{
int offset;
cout << "Offset: ";
cin >> offset;
return offset;
}
/**********************************************************************
* NUMDAYS
* Accepts the number of days from the user.
***********************************************************************/
int getNumDays()
{
int numDays;
cout << "Number of days: ";
cin >> numDays;
return numDays;
}