Originally Posted by
INeedSleep
Code:
//string names converted to roman numerals
string rome1="I";
string rome2="II";
string rome3="III";
string rome4="IV";
string rome5="V";
string rome6="VI";
string rome7="VII";
string rome8="VIII";
string rome9="IX";
string rome10="X";
string rome50="L";
string rome100="C";
string rome500="D";
string rome1000="M";
These should all be const, since you don't want to ever modify them. Also, it will help you to make an array of these so that you have similar numerals in an array together. So do something like this:
Code:
const char numerals[2][4]={
{'I','X','C','M'},
{'V','L','D','\0'} }
Code:
i=1;
n=input%10;
if (n == 4 || n == 9)
{
// handle 4 and 9 separately
}
else
{
// handle 5 ..and start 6,7,8
while(i<=n)
{
roman=roman+rome1;
i=i+1;
}
}
Instead of using rome1, put this in a loop. For each digit, print the corresponding roman numeral value. This is where having the above mentioned array helps.
Code:
if((cin.peek() != '\n'))//if input is greater than or equal to 1000
{
}
I don't know what This is supposed to do, but you already handled the 1000s place.
Code:
//trying to find the thousands spot
//the input cannot exceed 4000 and cannot be 4000 also input cannot be lower
//1000
else if( (input<4000 && input != 4000) && !(input < 1000) )
{
input=input/1000%10;//isolate the digit in the thousands place
//cout<<input;
}
//trying to find the hundreds spot
//the input cannot exceed 1000 and be less than 100
else if(input<1000 && input>=100)
{
input=input%1000/100;
//cout<<input;
}
else if(input<100 && input>=10)
{
input=input%100/10;
//cout<<input;
}
else if(input<10 && input>0 && input>=1)
{
input=input%10;
//cout<<input;
}
else
{
cout<<"nada";
}
You don't need all this. Handle each decimal place in a single loop.