Hello guys,
Thanks for your help and suggestions. I managed to solve this task without converting to string. Here is my code if someone is interested:
Code:#include <iostream> #include <cstdlib> using namespace std; void separate(int number) { // If the number is below 1000 - print it because it holds exactly or below 3 digits if (number < 1000) { cout << number; } else { int temp = number % 1000; // Variable which holds the remainder of the calculation (the last 3 digits of the integer) number = number / 1000; // Remove the last 3 digits and pass the remaining of the integer again to the function separate(number); cout << "," << temp; } } int main() { int input; cout << "Enter your number :" << endl; cin >> input; separate(input); cout << endl; system("PAUSE"); return 0; }




Reply With Quote