Write a program which will accept a Roman numeral input from the keyboard
and return to the screen its numeric value. Some of you cases should input unusual or
awkward input, and at least one trial must include an improperly formed Roman numeral.
The following features of the Roman numeral system are shown for review, and some
limitations are given to help ease the program’s complexity:

1. The following Roman numerals, with their Arabic equivalents, must be handled:
I – 1
V – 5 X – 10
L – 50
C – 100
D – 500
M – 1000

2. The Middle-Ages extension of the Roman numeral system which intended to shorten
notations (such as replacing VIIII by IX and XXXX by XL) will be avoided. The
program does not have to anticipate or handle subtractive prefixes.

3. All inputs will be in the range [1, ..., 500]. The program does not have to handle a zero,
and it does not have to work with Roman numerals larger than 1,000.


so what would you guys suggest? would functions be a good place to start, we only just learned them so i'm a little nervous about using them. if i should use them does anyone have any sudo code to help me out a little? or a direction for me to start?

how do i start?
i can't even figure out how to work the input

ok i've gotten somewhere.. but i don't know about this code, I'm about to test it.

#include <iostream>
#include <cmath>
#include <string>
using namespace std;

unsigned int romnum (string);

int main()
{
	
	unsigned int var=0;
	unsigned int 1=0;
	string roman_numeral;
	
	cout<<"Please enter a Roman Numeral (Note that IV is 6 	not 4)"<<endl;
	getline(cin, roman_numeral);
	
	for (unsigned int i=0;i<roman_numeral.size();++i)
		{
		romnum(roman_numeral);
		cout<<"The decimal value is "<<var<<endl;
		}
}
unsigned int romnum (roman_numeral)	
{	
		if (roman_numeral=='M')
			var +=1000
			
			else if (roman_numeral=='D')
			var +=500
			
			else if (roman_numeral=='C')
			var +=100
			
			else if (roman_numeral=='L')
			var +=50
			
			else if (roman_numeral=='X')
			var +=10
			
			else if (roman_numeral=='V')
			var+=5
			
			else if (roman_numeral=='I')
			var +=1	
}

ok i'm stuck again..

#include <iostream>
#include <cmath>
#include <string>
using namespace std;

unsigned int romnum (string);

int main()
{
	
	unsigned int var=0;
	string roman_numeral;
	
	cout<<"Please enter a Roman Numeral (Note that IV is 6 	not 4)"<<endl;
	getline(cin, roman_numeral);
	
	for (unsigned int i=0;i<roman_numeral.size();++i)
		{
		romnum(roman_numeral);
		cout<<"The decimal value is "<<var<<endl;
		}
}
unsigned int romnum (roman_numeral)	
{	
		if (roman_numeral=='M')
			var +=1000
			
			else if (roman_numeral=='D')
			var +=500
			
			else if (roman_numeral=='C')
			var +=100
			
			else if (roman_numeral=='L')
			var +=50
			
			else if (roman_numeral=='X')
			var +=10
			
			else if (roman_numeral=='V')
			var+=5
			
			else if (roman_numeral=='I')
			var +=1	
}

I don't understand how to use string in the code, i need help.
I'm also not sure this will work, can anyone tell from reading it if this will take a random input like XVI and read that it means 16?

Well i have worked out the code. And found that with some small corrections this code is working out.

The first mistake is in the declaration in line 6 doesnt match the declaration in line 23

unsigned int romnum (string);

Instead of that you can try using a character .

unsigned int romnum (char a);

Second. The variable that you are assigning the value is not found with most compilers as you have declared it in main and using it in another function.

This can however be avoided by declaring var globally.

And you missed in keeping the semicolons at the end of every line in the if and else if loops.

Instead of keeping the cout statement inside the for loop it will be better to keep it outside as you only want the output to be posted after the total calculation.

Okay i have corrected the total code and compiled it with DEV C++ and it works just fine.

HERE IS THE CODE.

#include <iostream>
#include <cmath>
#include <string>
using namespace std;

unsigned int romnum (char a);
unsigned int var=0;

int main()
{
	
	string roman_numeral;
	
	cout<<"Please enter a Roman Numeral (Note that IV is 6 	not 4)"<<endl;
	getline(cin, roman_numeral);
	
	for (unsigned int i=0;i<roman_numeral.size();++i)
		{
		romnum(roman_numeral[i]);
		}
		cout<<"The decimal value is "<<var<<endl;
}
unsigned int romnum (char a)	
{	
		if (a=='M'||a=='m')
			::var +=1000;
			
			else if (a=='D'||a=='d')
			::var +=500;
			
			else if (a=='C'||a=='c')
			::var +=100;
			
			else if (a=='L'||a=='l')
			::var +=50;
			
			else if (a=='X'||a=='x')
			::var +=10;
			
			else if (a=='V'||a=='v')
			::var+=5;
			
			else if (a=='I'||a=='i')
			::var +=1;	
}

omgosh, those are such dumb mistakes.. thank you so much it had me totally stumped

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.