C# :: Aufgabe #100 :: Lösung #4

9 Lösungen Lösungen öffentlich
#100

Jahreszahlenkonverter für römische Schreibweise

Anfänger - C# von BlackBird321 - 04.06.2015 um 22:36 Uhr
Bitte schreibe ein Programm, welches eine einzugebende Jahreszahl in eine römische Schreibweise umwandelt.

Beispiel:

1995 = MCMXCV
2015 = MMXV
#4
vote_ok
von n.rohde (400 Punkte) - 18.08.2015 um 16:35 Uhr
Quellcode ausblenden C#-Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JahrAlsRoemischeZahl
{
    class Program
    {
        static void Main(string[] args)
        {
            int jahreszahl;
            string roemischeZahl="";

            Console.Write("Bitte geben Sie eine Jahreszahl ein: ");
            jahreszahl = Convert.ToInt32(Console.ReadLine());
            
            while (jahreszahl != 0)
            {
                if ((jahreszahl-1000) >= 0)
                {
                    roemischeZahl += "M";
                    jahreszahl = jahreszahl - 1000;
                    continue;
                }
                else if ((jahreszahl - 900) >= 0)
                {
                    roemischeZahl += "CM";
                    jahreszahl = jahreszahl - 900;
                    continue;
                }
                else if ((jahreszahl - 500) >= 0)
                {
                    roemischeZahl += "D";
                    jahreszahl = jahreszahl - 500;
                    continue;
                }
                else if ((jahreszahl - 400) >= 0)
                {
                    roemischeZahl += "CD";
                    jahreszahl = jahreszahl - 400;
                    continue;
                }
                else if ((jahreszahl - 100) >= 0)
                {
                    roemischeZahl += "C";
                    jahreszahl = jahreszahl - 100;
                    continue;
                }
                else if ((jahreszahl - 90) >= 0)
                {
                    roemischeZahl += "XC";
                    jahreszahl = jahreszahl - 90;
                    continue;
                }
                else if ((jahreszahl - 50) >= 0)
                {
                    roemischeZahl += "L";
                    jahreszahl = jahreszahl - 50;
                    continue;
                }
                else if ((jahreszahl - 40) >= 0)
                {
                    roemischeZahl += "XL";
                    jahreszahl = jahreszahl - 40;
                    continue;
                }
                else if ((jahreszahl - 10) >= 0)
                {
                    roemischeZahl += "X";
                    jahreszahl = jahreszahl - 10;
                    continue;
                }
                else if ((jahreszahl - 9) >= 0)
                {
                    roemischeZahl += "IX";
                    jahreszahl = jahreszahl - 9;
                    continue;
                }
                else if ((jahreszahl - 5) >= 0)
                {
                    roemischeZahl += "V";
                    jahreszahl = jahreszahl - 5;
                    continue;
                }
                else if ((jahreszahl - 4) >= 0)
                {
                    roemischeZahl += "IV";
                    jahreszahl = jahreszahl - 4;
                    continue;
                }
                else if ((jahreszahl - 1) >= 0)
                {
                    roemischeZahl += "I";
                    jahreszahl = jahreszahl - 1;
                    continue;
                }
            }
            Console.WriteLine(roemischeZahl);
            Console.Read();
        }
    }
}

Kommentare:

Für diese Lösung gibt es noch keinen Kommentar

Bitte melden Sie sich an um eine Kommentar zu schreiben.
Kommentar schreiben