Answer the question
In order to leave comments, you need to log in
What's wrong with the software?
I recently started learning C++. There was a following problem. So, the program can read two integers A and B from the standard stream (0 < A ≤ B, and A and B are placed in int) and count how many integers are on the half-interval [A ; B) are divisible by 4 and not divisible by 100, or divisible by 400. Print the resulting number to standard output. To check divisibility, use the operator for finding the remainder of the division (%).
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
cout<<"Enter a and b:\n";
cin>>a,b;
с = a - b;
int i = 0;
for(int i = 0; i<c; c++)
while(c\4 & c%100 || c\400)
cout<<c
return 0;
}
Answer the question
In order to leave comments, you need to log in
There are a lot of things wrong here, first of all,
for(int c = 0; i<c; c++)
while(c\4 & c%100 || c\400)
cout<<c
1) code convention
2) if you can't do it without {}, then put {}
3) & it's not &&
4) doesn't it confuse the cycle in the cycle?
for(i = a + 4 - a % 4, c = 0;i<b;i+=4){
if (i % 100 == 0 && i % 400 != 0) continue;
c++;
}
It seems that you not only started learning C++, but found some example of a program (or rather a program?) that does not compile (but the teacher needs a working program (program?)). Here you are asking for a ready-made solution. If you didn’t even place semicolons everywhere - what can we talk about?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question