Cody

# Problem 44293. Write out numbers in words

Solution 3340678

Submitted on 23 Oct 2020
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
filetext = fileread('num2words.m'); assert(isempty(strfind(filetext, 'six hundred and seventy-nine'))) assert(isempty(strfind(filetext, 'one thousand, five hundred and twenty')))

2   Fail
x = 0; y_correct = 'zero'; assert(isequal(num2words(x),y_correct))

Error using vertcat Dimensions of arrays being concatenated are not consistent. Error in num2words (line 2) numbers = {'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', Error in Test2 (line 3) assert(isequal(num2words(x),y_correct))

3   Fail
x = 1; y_correct = 'one'; assert(isequal(num2words(x),y_correct))

Error using vertcat Dimensions of arrays being concatenated are not consistent. Error in num2words (line 2) numbers = {'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', Error in Test3 (line 3) assert(isequal(num2words(x),y_correct))

4   Fail
x = 56; y_correct = 'fifty-six' assert(isequal(num2words(x),y_correct))

y_correct = 'fifty-six'

Error using vertcat Dimensions of arrays being concatenated are not consistent. Error in num2words (line 2) numbers = {'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', Error in Test4 (line 3) assert(isequal(num2words(x),y_correct))

5   Fail
x = 100; y_correct = 'one hundred'; assert(isequal(num2words(x),y_correct))

Error using vertcat Dimensions of arrays being concatenated are not consistent. Error in num2words (line 2) numbers = {'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', Error in Test5 (line 3) assert(isequal(num2words(x),y_correct))

6   Fail
x = 105; y_correct = 'one hundred and five'; assert(isequal(num2words(x),y_correct))

Error using vertcat Dimensions of arrays being concatenated are not consistent. Error in num2words (line 2) numbers = {'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', Error in Test6 (line 3) assert(isequal(num2words(x),y_correct))

7   Fail
x = 245; y_correct = 'two hundred and forty-five'; assert(isequal(num2words(x),y_correct))

Error using vertcat Dimensions of arrays being concatenated are not consistent. Error in num2words (line 2) numbers = {'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', Error in Test7 (line 3) assert(isequal(num2words(x),y_correct))

8   Fail
x = 679; y_correct = 'six hundred and seventy-nine'; assert(isequal(num2words(x),y_correct))

Error using vertcat Dimensions of arrays being concatenated are not consistent. Error in num2words (line 2) numbers = {'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', Error in Test8 (line 3) assert(isequal(num2words(x),y_correct))

9   Fail
x = 1520; y_correct = 'one thousand, five hundred and twenty'; assert(isequal(num2words(x),y_correct))

Error using vertcat Dimensions of arrays being concatenated are not consistent. Error in num2words (line 2) numbers = {'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', Error in Test9 (line 3) assert(isequal(num2words(x),y_correct))

10   Fail
x = 9999; y_correct = 'nine thousand, nine hundred and ninety-nine'; assert(isequal(num2words(x),y_correct))

Error using vertcat Dimensions of arrays being concatenated are not consistent. Error in num2words (line 2) numbers = {'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', Error in Test10 (line 3) assert(isequal(num2words(x),y_correct))

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!