Bevo
Nah
+718|6492|Austin, Texas
Hey guys,

I'm trying to write a program in C++ that breaks when it find suitable numbers for a, b, c, d, e, f, g, h, and i through nested for loops, but for some reason it's not working properly. There's a series of mathematical operations that these 9 ints needs to enter and none of them can equal each other (a through i = an int 1-9 where no ints are repeated).

It seems to run the equation check OK (it breaks when the function ==100), but it doesn't run the variable check correctly for some reason, it spits out lots of numbers that are similar to each other, and I don't know why. When I run tests outside of these for loops with similar approaches they work fine, but not inside for some reason. Halp.

running the if statement

if ((sum==100)&&(a!=b!=c!=d!=e!=f!=g!=h!=i))
{
   cout << output;
   break;
}

Which works outside of the for loops, but inside it seems to ignore the whole integers equaling each other part.

Last edited by Bevo (2011-02-24 16:47:42)

HaiBai
Your thoughts, insights, and musings on this matter intrigue me
+304|5455|Bolingbrook, Illinois
a!=b!=c

this should be two different conditional statements:

a != b && b != c

but you have to do that to all of them.

however, since you don't want any of the numbers to equal each other, you're going to have to extend that:

if ((sum==100)&&(a != b && a != c && a != d && b != c && b != d && c != d))

since you're doing nested for loops, add the conditional checks for numbers as soon as possible.  for example:

for(a = 0, a <= 10, a++)
{
    for(b = 0, b <= 10, b++)
    {
        if(a != b)
        {
            for (c = 0, c <= 10, c++)
            {
            }
        }
    }
}
Camm
Feeding the Cats.
+761|4939|Dundee, Scotland.
http://pastebin.com/ pop it in here so I can have a look at it?
for a fatty you're a serious intellectual lightweight.

Board footer

Privacy Policy - © 2024 Jeff Minard