1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
#include <cmath>
#include <iostream>
using namespace std;
int i=0, j, number;
int nof1000, nof500, nof100, nof50, nof10, nof5, nof1;
char roman_result[100000];
int roman_conversion(char, int);
//This my other function that will assign a letter to the roman_result array
int roman_conversion(char RC, int num)
int j;
for (j=0; j<num, j++)
roman_result[j]=RC;
int main(int argc, char *argv[])
{
while (number!=0)
{
if (number>=1000)
{
nof1000=number/1000;
roman_conversion('M',nof1000);
number=number-nof1000*1000;
}
else if (number>=500)
{
if (number>=900){
roman_result[i++]='C';
roman_result[i++]='M';
number=number-900;
}
else{
nof500=number/500;
roman_conversion('D',nof500);
number=number-500;
}
}
else if (number>=100)
{
if (number>=400){
roman_result[i++]='C';
roman_result[i++]='D';
number=number-400;
}
else{
nof100=number/100;
roman_conversion('C',nof100);
number=number-100;
}
}
else if (number>=50)
{
if (number>=90){
roman_result[i++]='X';
roman_result[i++]='C';
number=number-90;
}
else{
nof50=number/50;
roman_conversion('L',nof50);
number=number-50;
}
}
else if (number>=10)
{
if (number>=40){
roman_result[i++]='X';
roman_result[i++]='L';
number=number-40;
}
else{
nof10=number/10;
roman_conversion('L',nof10);
number=number-10;
}
}
else if (number>=5)
{
if (number>=9){
roman_result[i++]='I';
roman_result[i++]='X';
number=number-9;
}
else{
nof5=number/5;
roman_conversion('V',nof5);
number=number-5;
}
}
else if (number>=1)
{
if (number>=4){
roman_result[i++]='I';
roman_result[i++]='V';
number=number-4;
}
else{
nof1=number;
roman_conversion('I',nof1);
number=number-1;
}
}
cout<<"The roman numeral equivalent is ";
//This should print out the results of the array roman_result depending on the value of j
for (j=0;j<i;j++)
cout<<roman_result[j];
system("PAUSE");
return EXIT_SUCCESS;
}
|