Code:
#include<iostream>
#include<string>
using namespace std;
int main()
{
short x;
string roman;
cout << "Enter your number:"<<endl;
cin >> x;
while (!(x < 4000 && x > 0)) // I should probably DeMorgan's this...
{
cerr << "\n\aInvalid range! Your value must be between 1 "
"and 3999!\nSo sayeth the Emperor!\n\n";
cout << "Enter your number:"<<endl;
cin >> x;
}
// need to 'combine' things so that they can do non-exact multiples: 1776, 931, 452, 8, ...
if(x == 1000)
{
roman = "M";
}
else if(x == 500)
{
roman = "D";
}
else if(x == 100)
{
roman = "C";
}
else if(x == 50)
{
roman = "L";
}
else if(x == 10)
{
roman = "X";
}
else if(x == 5)
{
roman = "V";
}
else if(x == 1)
{
roman = "I";
}
// x/1000 = t;
// count << "M" * t <<endl;
// print out t amout of times
cout << x << " translated to Roman Numerals is " << roman << ".\n";
return 0;
}
i only learned branching,looping,and string, and few basic things
how should i combine the things and do the non-exact number?
thank you for helping me