Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static string ToRoman(int arabic)
        {
            int[] values = new int[] { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 };
            string[] numerals = new string[] { "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" };
            string input = "";
            for (int i = 0; i < arabic; i++)
            {
                while (arabic >= 1000)
                {
                    input = input + "M";
                    arabic = arabic - 1000;
                }
                while (arabic >= 900)
                {
                    input = input + "CM";
                    arabic = arabic - 900;
                }
                while (arabic >= 500)
                {
                    input = input + "D";
                    arabic = arabic - 500;
                }
                while (arabic >= 400)
                {
                    input = input + "CD";
                    arabic = arabic - 400;
                }
                while (arabic >= 100)
                {
                    input = input + "C";
                    arabic = arabic - 100;
                }
                while (arabic >= 90)
                {
                    input = input + "XC";
                    arabic = arabic - 90;
                }
                while (arabic >= 50)
                {
                    input = input + "L";
                    arabic = arabic - 50;
                }
                while (arabic >= 40)
                {
                    input = input + "XL";
                    arabic = arabic - 40;
                }

                while (arabic >= 10)
                {
                    input = input + "X";
                    arabic = arabic - 10;
                }
                while (arabic >= 9)
                {

                    input = input + "IX";
                    arabic = arabic - 9;
                }
                while (arabic >= 5)
                {
                    input = input + "V";
                    arabic = arabic - 5;
                }
                while (arabic >= 4)
                {
                    input = input + "IV";
                    arabic = arabic - 4;
                }
                while (arabic >= 1)
                {
                    input = input + "I";
                    arabic = arabic - 1;
                }
            }
            return input;
        }
        static void Main(string[] args)
        {
            for (int NUMERAL = 0; NUMERAL <= 4000; NUMERAL++)
            {
                while (NUMERAL <= 4000)
                {
                    int x = 1;
                    while (x < 20)
                    {
                        Console.WriteLine((x + NUMERAL) + " = " + ToRoman(x + NUMERAL));
                        x = x + 1;
                    }
                    NUMERAL = x + NUMERAL;
                    Console.WriteLine(NUMERAL + " = " + ToRoman(NUMERAL));
                    Console.WriteLine("Press any key for the next 20 numbers");
                    Console.ReadKey(true);

                }
            }
        }
    }
}
Posted
Updated 12-Jul-12 7:27am
v4
Comments
Sergey Alexandrovich Kryukov 11-Jul-12 21:02pm    
This is not a question. If you "don't know where to begin", what does your code mean? What's the problem? You can use "improve question" above. Without proper improvement of the question, you cannot hope for help. Besides, I would recommend you to write more accurate code first. All those hard-coded 400, 500, 20, 4000, "I", "IX", especially matching to numerals are not acceptable at all.
--SA
D5927 11-Jul-12 21:04pm    
i am writing this project that acts as a arabic to roman numeral converter and lists them in a console application up to 4000 i need help writing a new class which would include 2 columns instead of one and display 100 numbers instead of 20. i would like some advice as how i would be able to start the new class
lukeer 12-Jul-12 2:46am    
A comment is not the proper place for such information. As Sergey Alexandrovitch Kryukov said, update your question using the "Improve question" link for that.

Besides, see my answer.
Zoltán Zörgő 12-Jul-12 3:12am    
Ok, but if you want 100 numbers per page in two columns, that means 50 numbers in a column. This on other hand means, that you need to have 50 rows on the console. Otherwise pagination has no sense, since user must scroll the screen. By default you have 25 rows (and 300 as buffer), but users can set console size as they want. How will you manage this?

You don't need another class. Just tweak your output a little. This completely untested code may work:
C#
for (int i = 0; i < 4000; i += 2)
{
    Console.WriteLine(i.ToString() + " = " + ToRoman(i) + "\t\t" + (i + 1).ToString() + " = " + ToRoman(i + 1));
    if (i % 100 == 0 || (i + 1) % 100 == 0)
    {
        Console.WriteLine("Press any key for the next 100 numbers");
        Console.ReadKey(true);
    }
}
 
Share this answer
 
v2
Comments
Zoltán Zörgő 12-Jul-12 3:08am    
Good suggestion, but needs some modification if data has to be presented in column flow, not in row flow.
D5927 12-Jul-12 13:25pm    
good answer but my project requires for me to put in a new class. Any advice on that
As you have few items to display, use buffer array. Dimension it to have two columns and as many rows a the console has. (see: System.Console.WindowHeight[^]). Then fill the first column, then the second. When displaying, parse the array row by row.
Or you can simply use the SetCursorPosition[^] method to place the cursor on the screen, and display your data in columns.
 
Share this answer
 
v2
Comments
Zoltán Zörgő 12-Jul-12 14:31pm    
It would be fair to have a feedback on a downvote :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900