is there any way i might be able to interrupt loops at given points

i am making this calendar program and i am wondering if there is any way to interrupt loops at a predetermined point?(7):
#include <iostream>
#include <iomanip>
#include <fstream>
#include <ctime>

using namespace std;
bool isleapyear(int);
int daysinmonth(int, bool);
int daysoftheweek(int, int);
int main()
{
int m, i;
cout << "Number Month: " << endl;
cin >> m;
cout << "year: ";
cin >> i;
int h = daysoftheweek(m, i);
bool l = isleapyear(i);
int d = daysinmonth(m, l);
cout << setw(5) << "SUN" << setw(5) << "MON" << setw(5) << "TUE" << setw(5) << "WED" << setw(5) << "THU" << setw(5) << "FRI" << setw(5) << "SAT" << endl;
for (int x = 0; x <= d; x++)
{
cout << setw(5) << h;
h++;
}
cout << endl;
system("pause");
return EXIT_SUCCESS;
}
int daysoftheweek(int m, int i)
{
int h, k, j;
k = i;
j = i;
k = k % 100;
j = j / 100;
if (m < 3)
{
m = m + 12;
k = k - 1;
}
h = (1 + ((13 * (m + 1)) / 5) + k + (k / 4) + (j / 4) + 5 * j) % 7;
if (h != 0)
{
h = h - 1;
}
else
{
h = 6;
}
return h;
}
bool isleapyear(int x)
{
bool result = false;
if (x % 4 == 0)
{
result = true;
if (x % 100 == 0)
{
result = false;
if (x % 400 == 0)
{
result = true;
}
}
}
return result;
}
int daysinmonth(int x, bool leapyear)
{
int result;
if (x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12)
{
result = 31;
}
else if (x != 2)
{
result = 30;
}
else if (x == 2 && leapyear)
{
result = 29;
}
else
{
result = 28;
}
return result;
}
Topic archived. No new replies allowed.