Converting integer to Roman Numeral

前端 未结 9 1302
轮回少年
轮回少年 2020-12-16 08:27

I have a test due in about four hours and one of the questions asks us to convert a user-inputed integer up to 100 into a roman numeral. I think my code is very close (I fou

9条回答
  •  北海茫月
    2020-12-16 08:47

    Function to Convert Decimal to Roman Numrals string toLongRoman(int x) {

    string Romanvalue;
    
    string  Roman[13] = { "M","CM","D","CD", "C","XC", "L","XL", "X","IX","V","IV", "I" };
    int Numbers[13] = { 1000, 900, 500,400, 100,90,50,40,10,9,5,4,1 };
    
    for (int index = 0; index < 13; index++) {
    
    
    
            while (x >= Numbers[index]) {
                Romanvalue += Roman[index];
    
    
                x -= Numbers[index];
    
            }
        }
    
        return Romanvalue;
    

提交回复
热议问题