I need a help on this matter, and here is the question
"Write a program that converts a number entered in Roman Numerals to decimal/integer. Your program should consist a class, say Roman. An object of type should do the following:"
Store the number as a Roman numeral
Convert and store the number into decimal
Print the number as a Roman numeral or decimal number as requested by the user.
The decimal values of the Roman numerals are:
M 1000
D 500
C 100
L 50
X 10
V 5
I 1
Test your program using the following Roman Numerals: MCXIV, CCLIX and MDCLXVI
and here is my code:
I already have the code downloaded in the internet and I edit it
Note: I did not create a class yet.
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(" enter roman numerals: ");
String rom = Console.ReadLine();
//int length=[ ];
int dc;
//decimal dc=length;
//int rom[length];
//int length =length;
int i;
try
{
for (i = 0; i < 10; i++)
{
switch (rom[i])
{
case 'M':
case 'm':
dc = 1000;
//if (dc < dc)
//{
// dc -= dc;
// Console.WriteLine(dc);
//}
//else
//{
// dc += dc;
// Console.WriteLine(dc);
//}
Console.WriteLine(dc);
break;
case 'D':
case 'd':
dc = 500;
Console.WriteLine(dc);
break;
case 'C':
case 'c':
dc = 100;
Console.WriteLine(dc);
break;
case 'L':
case 'l':
dc = 50;
Console.WriteLine(dc);
break;
case 'X':
case 'x':
dc = 10;
Console.WriteLine(dc);
break;
case 'V':
case 'v':
dc = 5;
Console.WriteLine(dc);
break;
case 'I':
case 'i':
dc = 1;
Console.WriteLine(dc);
break;
//default:
//Console.Write("error:");
}
}
}
catch (IndexOutOfRangeException e){}
}
}
}
Question
Gil37
Good day/eve to all members here in Neowin.net
I need a help on this matter, and here is the question
"Write a program that converts a number entered in Roman Numerals to decimal/integer. Your program should consist a class, say Roman. An object of type should do the following:"
The decimal values of the Roman numerals are:
Test your program using the following Roman Numerals: MCXIV, CCLIX and MDCLXVI
and here is my code:
I already have the code downloaded in the internet and I edit it
Note: I did not create a class yet.
Program.cs
Link to comment
Share on other sites
16 answers to this question
Recommended Posts