Hello,
I have to prepare a program that from the year interval [m;n] selects the year that the festival took place and next to that year also shows which festival was it counting from the first one. The festivals have been held since the 1950s and take place every four years.
Given year interval is [1984;2007].
I made a program like this:
#include <iostream>
#include<cmath>
using namespace std;
int main()
{
int m, n, x, y;
cout<<"Enter first given year"<<endl;
cin>>m;
cout<<"Enter second given year"<<endl;
cin>>n;
y=0;
for (x=1950; x<=n; x++)
{
if (((1950-x)%4==0)&&(y=y+1))
cout<<x<<" "<<y<<endl;
}
}
My main problem is that I get the year starting from 1950, like this:
1950 1
1954 2
1958 3
1962 4
1966 5
1970 6
1974 7
1978 8
1982 9
1986 10
1990 11
1994 12
1998 13
2002 14
2006 15
#include <iostream>
int main() {
int m {}, n {};
std::cout << "Enter first given year: ";
std::cin >> m;
std::cout << "Enter second given year: ";
std::cin >> n;
for (int x = 1950, y = 0; x <= n; ++x)
if (((1950 - x) % 4 == 0) && ++y && x > m)
std::cout << x << " " << y << '\n';
}
Enter first given year: 1984
Enter second given year: 2007
1986 10
1990 11
1994 12
1998 13
2002 14
2006 15
Thank you, I worked it out. And thank you for mentioning that, my teacher isn’t really teaching those things and never mentioned it so I am glad you told me that it is important, I will be sure to learn those!