0

This code was part of my first quarter 2nd semester project for a subject called programming 2.

its a simple roman to arabic convertion function.

#include <iostream>
#include <cstring>

using namespace std;

// prototype for function
int romano_dec();

int main(int argc, char *argv[])
{
romano_dec();
system("PAUSE");
return EXIT_SUCCESS;
}

int romano_dec()
{
     char roman_num[10];
	 cout << "Por favor ingrese un numero romano: ";
	 cin >> roman_num;
	 int len = strlen(roman_num);
	 int number = 0;
	 int counter = 0;
	 int b4sum = 0;
	 int sum = 0;

	 for (counter = len; counter >= 0; counter--)
		 {
			 if (roman_num[counter] == 'M' || roman_num[counter] == 'm')
				 number = 1000;
			 else if (roman_num[counter] == 'D' || roman_num[counter] == 'd')
				 number = 500;
			 else if (roman_num[counter] == 'C' || roman_num[counter] == 'c')
				 number = 100;
			 else if (roman_num[counter] == 'L' || roman_num[counter] == 'l')
				 number = 50;
			 else if (roman_num[counter] == 'X' || roman_num[counter] == 'x')
				 number = 10;
			 else if (roman_num[counter] == 'V' || roman_num[counter] == 'v')
				 number = 5;
			 else if (roman_num[counter] == 'I' || roman_num[counter] == 'i')
				 number = 1;
			 else
				 number = 0;

			 if (b4sum > number)
				 sum = b4sum - number;
			 else
				 sum = sum + number;
			 b4sum = number;
		}

	cout << "El resultado es: " ;
    cout << sum << endl;
}
3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by JLChafardet
0

You actually have one problem, your function (romano_dec) is an INT function, and it must return some kinda a value, so if you only make it void, or return anything.

btw, you're code is nice and works perfect

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.