C
C
cccchhhhbbbb2014-09-20 20:04:10
C++ / C#
cccchhhhbbbb, 2014-09-20 20:04:10

How to implement this cycle correctly?

I just started learning C++: I'm getting acquainted with cycles, and the following problem arose, I give a piece of code:

for(year = 2014; year <=2114; year++)//допустим, есть некоторое значение года, стартуем с 2014 до 2114
   {
         int ostYear = year%10;//находим остаток от года
if(ostDay == ostYear || ostMonth == ostYear);// если остаток от года совпадает с остатком от дня или месяца (они были объявлены ранее), то нужно вывести этот год, если нет - продолжить поиск
        cout<<year;

Not working, please help with the implementation, thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lolshto, 2014-09-20
@Lol4t0

Extra semicolon:

if(ostDay == ostYear || ostMonth == ostYear);
                                           ^^^^^

And yet rem, remainder, not ostatok :)
And it’s not at all necessary to sort through all the years when you can immediately find only those that are needed
int minN = std::min(remDay, remMonth);
int maxN = std::max(remDay, remMonth);
for(year = 201; year <=211; year++)
{
        cout << year << MinN << '\n' << year << maxN;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question