#include #include using namespace std; int main() { const string morse[] { "-----", ".----", "..---", "...--", "....-", ".....", "-....", "--...", "---..", "----." }; const size_t n {size(morse)}; cout << "Please type a non-negative integer: "; int x {0}; cin >> x; if (!cin) { cerr << "Sorry, that wasn't a number.\n"; return EXIT_FAILURE; } if (x < 0) { cerr << "Sorry, the number must be non-negative.\n"; return EXIT_FAILURE; } int digitArray[50] {}; int count {0}; if (x == 0) { digitArray[0] = 0; count = 1; } else { while (x > 0) { digitArray[count] = x % 10; x /= 10; ++count; } } for (int i {count - 1}; i >= 0; --i) { cout << morse[digitArray[i]]; if (i > 0) { cout << ' '; } } cout << "\n"; return EXIT_SUCCESS; }