I tried this again using type float instead of double and there is no segmentation error this time.....