S
S
Sterben2014-09-28 18:11:30
C++ / C#
Sterben, 2014-09-28 18:11:30

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;
}

I ask you to help put the code in order and, if it doesn’t make it difficult for someone, give a solution, thank you :)

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alex Chistyakov, 2014-09-28
@alexclear

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

& is a bitwise AND, what does this operator do in a boolean expression?
Second, there is no \ operator in C++.
Thirdly, in such formatting of the code, it is generally not clear what the author wanted to say, always, if possible, use operator brackets { and }, do not make people guess.

L
lookid, 2014-09-28
@lookid

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?

S
Sergey, 2014-09-28
Protko @Fesor

for(i = a + 4 - a % 4, c = 0;i<b;i+=4){
    if (i % 100 == 0 && i % 400 != 0) continue;
    c++;
}

M
Michael., 2014-09-29
@kulinich

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 question

Ask a Question

731 491 924 answers to any question