I'm new to programming and I just need help because I'm stuck. We need to make a program that will turn arab numbers from 1 to 50 to roman numbers, but when you write a number bigger than 50 it should say that the number is out of given borders.
I thought to use string and switch, but no matter how much I tried, I don't know what to do next.
I found a similar program that writes all the roman numbers and tried to use that code, but I cannot make it write just the numbers from 1 to 50.
Hope someone can help.
#include <iostream>
usingnamespace std;
string rim (int a, int b)
{
string s = "";
switch (a)
{
case 0: s = s + ""; break;
case 1: s = s + "X"; break;
case 2: s = s + "XX"; break;
case 3: s = s + "XXX"; break;
case 4: s = s + "XL"; break;
case 5: s = s + "L"; break;
default: cout << "The number is not in the given borders." << endl;
}
switch (b)
{
case 0: s = s + ""; break;
case 1: s = s + "I"; break;
case 2: s = s + "II"; break;
case 3: s = s + "III"; break;
case 4: s = s + "IV"; break;
case 5: s = s + "V"; break;
case 6: s = s + "VI"; break;
case 7: s = s + "VII"; break;
case 8: s = s + "VIII"; break;
case 9: s = s + "IX"; break;
default: cout << "The number is not in the given borders." << endl;
}
return s;
}
main()
{
int n, n1, n2;
cout << "Type a number between 1 and 50: ";
cin >> n;
n2 = n/10%10;
n1 = n%10;
cout << "Your roman number is " << rim( n2, n1 ) << "." << endl;
return 0;
}