Hi, I am only beginning C#, so bear with me. I have been given this program to write. This is the question:


Write a C# application called WRITENUM that inputs a number between 0 and 2,000,000,000 inclusive and outputs that number in textual form, as we would say it or write it normally. For example if we input 1234011811 then the program will output “One billion, two hundred and thirty four million, eleven thousand, eight hundred and eleven.” If we input 0 then the program will output “Zero”. Note that commas and “and”s have been appropriately placed, the first letter of the output is capitalised, words are separated using a single space and the text ends with a full stop. A program such as this might be used as part of a financial package that prints cheques as part of its output, for example.

Your program will create a single form (window) that will allow the user to enter the number at the top and produce the textual equivalent in the middle. The form will have two buttons, a “Convert to text” button which will cause the number input by the user to be shown in textual format. The second button will be an “Exit” button which will cause the program to terminate. The program will allow the user to perform conversions until the program is terminated.

The values supplied by the user must be input into a variable of type int.


Now, I want to know is there a way to do this without having loads of if and else statements checking the numbers entered?

Try using a switch( var.Length ) construct. That should limit you to ten or so case statements.

This sounds like an interesting project.

I'll be able to help you with something like this. However it's going to be a bit of time before i can get something started for you.

are you using Visual c# 2005 or 2008?
do the commas need to be automatically placed in the text box as the user inputs the number, or is it required that the user place the comma's themselves?

This sounds like an interesting project.

I'll be able to help you with something like this. However it's going to be a bit of time before i can get something started for you.

are you using Visual c# 2005 or 2008?
do the commas need to be automatically placed in the text box as the user inputs the number, or is it required that the user place the comma's themselves?

The user just enters a number in a text box and when they click on the 'Convert to text' button, it displays the text as in the question. I am using SharpDevelop.

Alright I've completed the working code for this, I didn't use cases and well it's sloppy, but works. It's terribly long so i do not feel comfortable pasting the entire code. I will paste the the modules in a tutorial type format, so that i can explain the code. I'll be back to edit in a moment

For some reason it won't let me edit one of my last post, so sorry for double posting. But here it goes

what I'm going to do, cause this started getting very long, I'm going to post the source code to the program i created earlier for download. You can take what you want from it, but be advised that it's very sloppy, and should not be used as reference in programming.

I hope this helps here's the code, its zipped.
Convert to Text

Here's a better link this link is direct, no password required. Sorry about that.

The program works fine. Thanks for your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.