Just bought a Mac for the first time.
Running OS X 10.5.3 with g++ version 4.0.1 on an Intel iMac.
This code gives incorrect solutions when I run it on this computer but gives the correct solution on my Debian box.
Just wondering what I'm missing on the Mac. Any help would be awesome.
Running OS X 10.5.3 with g++ version 4.0.1 on an Intel iMac.
This code gives incorrect solutions when I run it on this computer but gives the correct solution on my Debian box.
Code:
#include <iostream>
#include <iomanip>
#include <math.h>
int main(){
unsigned long int sum1, sum2, sum3, whereIam(6), lastHouse;
int numberHouses(0);
while(numberHouses != 10){
sum1 = (whereIam*(whereIam-1))/2;
lastHouse = static_cast<int>(-0.5 + 0.5*sqrt(1 + 8*whereIam*whereIam));
sum3 = (whereIam*(whereIam+1))/2;
sum2 = lastHouse*(lastHouse+1)/2 - sum3;
while(sum1 > sum2){
lastHouse++;
sum2 = lastHouse*(lastHouse+1)/2 - sum3;
}
if(sum1 == sum2){
numberHouses++;
std::cout << std::setw(10) << whereIam << std::setw(10) << lastHouse << std::endl;
}
whereIam++;
}
}
Just wondering what I'm missing on the Mac. Any help would be awesome.