lucky ticket with if and for loop

Hey, I need to do this task: Ticket has six numbers. ticket is lucky, if the sum of 3 first of it's numbers is equal to sum of its last three numbers. You are given 2 ticket numbers a and b (100000<=a<=b<=999999). Find all the possible lucky numbers in interval[a;b]. BUT I dont receive any output. HELP!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  #include<iostream>

using namespace std;
int main ()
{

int a,b,c;
cin>>a>>b;//2 numbers of tickets

for(int i=a;i<=b;i++){
c>a&&c<b;
    if((c/100000+(c/10000)%10+(c/100)%10)==((c%1000)/100+(c%100/10)+c%10))
cout<<c;
}



return 0;

}
Last edited on
c>a&&c<b;
This does nothing.

Line 12 appears to be doing things with the value of c, but c is some random value because you never assign any value to c.

Nowhere in your code do I see anything involving the sum of the first three numbers.

The code you've written has nothing to do with the problem to be solved. You need to think first about how to solve the problem, and then code.
Last edited on
In line 12 I make the sum of first three numbers and then I add "==" to compare it to he sum of last three numbers.
What is the value of c? Where did you assign this variable an actual value?

Do you realize that there are no fractions when working with integers. Ie. 1 / 1000 will yield zero.

In line 12 I make the sum of first three numbers

No, you work on the random number c.


c>a&&c<b;
I'm guessing that this is you trying to sort of say that you wish c was bigger than a, and less than b. That's nice, but it's not how C++ works. If you want c to have a value, you have to set that value yourself.
Last edited on
Topic archived. No new replies allowed.