Converted the program from c to c++