My friend Hassan is a teacher and he is responsible for printing students' certificates where the certificates must contain a student's total degree written in Arabic. So he asked me for a program that accepts Arabic number and returns the equivalent Arabic text.
Using the code
At the first, Hassan proposed to check the input number directly, so his code looked like this:
else if(num==1) output="One";
My idea is to divide the number to four sections:
Num4 = (int)Number / 1000;
Num5 = Number % 1000; Num1 = (int)Num5 / 100;
Num0 = Num5%100; Num2 = (int)Num0 / 10; Num3 = Num0%10;
So, we get count of ones in Num3, tens in Num2, hundreds in Num0 and thousands in Num5, and then we can compare each individual Num with its range:
Num3 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9),
Num2 (0, 10, 20, 30, 40, 50, 60, 70, 80, 90),
Num0 (0, 100, 200, 300, 400, 500, 600, 700, 800, 900)
And Num0 (0, 1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000)
At the end, we get a string which is an equivalent Arabic text, with 40 (
if) clauses only.
You can use this code in any application like the demo project that comes with this tutorial:
private void textBox1_TextChanged(object sender, System.EventArgs e)
Points of Interest
You can change Arabic strings to English strings or any language to get the same result.
Don't forget to enable Arabic script to your Windows to be able to view the code well.