### code puts out nothing

I have no clue whats wrong here but the code doesn't put out anything
this might be something really basic that i overlooked
the "cout << TenQuintillion" was a test to see if it was a problem further down

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950`` `````` #include using namespace std; int main() { int OutCount; double SideA = 3; double SideB = 4; double A; double B; double TotalA; double TotalB; double TenQuintillion; TenQuintillion = 10 * 1000 * 1000 * 1000 * 1000 * 1000; cout << TenQuintillion; while (SideB < 101) { while (TotalB < TenQuintillion) { TotalA = A / 2 * ((SideA - 2) * A - (SideA - 4)); TotalB = B / 2 * ((SideB - 2) * B - (SideB - 4)); if (TotalA > TotalB) { B = B + 1; } else if (TotalA == TotalB) { A = A + 1; B = B + 1; cout << TotalA << " "; if (OutCount % 10 == 0) { cout << "\n"; } } else { A = A + 1; } } OutCount = 0; cout << "\n\n\n"; if (SideB < 100) { SideB = SideB + 1; } else { SideA = SideA = 1; SideB = SideA = 1; } } return 0; } ``````

after a bit of messing around i found out that without the while loops the code gives an output however the answer is far off even using long long variables
Last edited on
Not entirely sure what's wrong, but variables A and B are uninitialized.
Try this:
 ``12`` ``````double A=0; double B=0;``````

That's a common issue.
Essentially, you never tell the code what A and B start as. See what I mean?
Last edited on
I think the problem is totalA == totalB. Comparison between doubles is not reliable. Try doing if(floor(totalA) == floor(totalB)) for which you will need <cmath>

floor(n) rounds a double (or float) down to the nearest integer.
neither worked :/
I think I'll just start over in a new file and see if that works it shouldn't take long

 ``123456`` `````` while (TotalB < TenQuintillion) //totalB = ??? //OutCount = ??? //initialize all your variables you can't use them in the program with no values ``````

That is your first problem. I am going to look at the rest of the code
I subbed some values in your code to either 0 or 1.

also you can't initialize them to 0. You can't divide by 0.
 ``123`` `````` TotalA = A / 2 * ((SideA - 2) * A - (SideA - 4)); TotalB = B / 2 * ((SideB - 2) * B - (SideB - 4)); ``````

A and B don't have values.

Then your using outcount with out a value
 `` `` ``if (OutCount % 10 == 0)``

It will never exit your first loop
 `` `` `` while (SideB < 101)``

because sideb will never be greater than 101 because you have this

 ``12`` `````` if (SideB < 100) { SideB = SideB + 1;``````

sideb wont go over 100
Even if you do manage to change that you just set them back to 1 anyway so it will never exit in the while loop

 ``12`` `````` SideA = SideA = 1; SideB = SideA = 1;``````

There is plenty more important things you missed I have to go to work though
Last edited on
One last thing, When I get output I have to scroll to the top of the page remove the /n/n/n
A small comment. Instead of this:
 ``12`` ``````double TenQuintillion; TenQuintillion = 10 * 1000 * 1000 * 1000 * 1000 * 1000;``````

just put
`double TenQuintillion = 1e16;`
wait Gkneeus you get output?
in the command prompt window i get it does absolutely nothing
also i did initialize all variables and that didn't help
the loop will finish when SideA = 100
and i tried starting with A and B at 1 which still didnt do anything
i made a new file and rewrote the code and it worked
although in the first edition i forgot to put A, B TotalA, and TotalB = 0 after the end of the inner loop
i think the first file must have glitched because the second one worked just fine
ran the file with fstream and noticed i forgot to exclude divisible side lengths resulting in a 1.2 GB text file (which notepad can't open) and i didn't even let the process play through more than a hundredth of the way
Topic archived. No new replies allowed.