The modulus operator from Christopher League on Vimeo.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout << "Enter start day (0=Sun, 6=Sat): ";
int start;
cin >> start;
cout << "Enter number of days: ";
int days;
cin >> days;
cout << "Sun Mon Tue Wed Thu Fri Sat\n";
// Indent to start day.
int spaces = start * 4;
cout << setw(spaces) << "";
for(int i = 1; i <= days; i++)
{
cout << setw(3) << i << " ";
if((i%7 + start) % 7 == 0)
{
cout << "\n";
}
}
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout << "Enter start day (0=Sun, 6=Sat): ";
int start;
cin >> start;
cout << "Enter number of days: ";
int days;
cin >> days;
cout << "Sun Mon Tue Wed Thu Fri Sat\n";
// Indent to start day.
int spaces = start * 4;
cout << setw(spaces) << "";
for(int i = 1; i <= days; i++)
{
cout << setw(3) << i << " ";
start++;
if(start == 7)
{
cout << "\n";
start = 0;
}
}
return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout << "Enter start day (0=Sun, 6=Sat): ";
int start;
cin >> start;
cout << "Enter number of days: ";
int days;
cin >> days;
cout << "Sun Mon Tue Wed Thu Fri Sat\n";
int day = 1 - start;
for(int row = 1; row <= 6; row++)
{
for(int col = 0; col < 7; col++)
{
if(day <= 0 || day > days)
{
cout << " ";
}
else
{
cout << setw(3) << day << " ";
}
day++;
}
cout << "\n";
}
return 0;
}