I'm writing a program that converts a roman numeral to a decimal value.
On line 28, I get an error that says: invalid conversion from `char*' to `char'.
// Roman numeral to decimal converter
#include <cstdlib>
#include <iostream>
usingnamespace std;
constint VALUE_I = 1;
constint VALUE_V = 5;
constint VALUE_X = 10;
constint VALUE_L = 50;
constint VALUE_C = 100;
constint VALUE_D = 500;
constint VALUE_M = 1000;
void PrintDecimal(int);
int Converter(char);
int GetValueOfChar(char, int);
int main()
{
char numRoman[6];
int numDecimal;
cout << "Enter roman numeral: ";
cin >> numRoman;
numDecimal = Converter(numRoman); // <---- ERROR HERE
PrintDecimal(numDecimal);
system("PAUSE");
return 0;
}
int Converter(char romanNum[])
{
int decimal = 0;
int current, next;
for(int i=0; i<6; i++){
// Gets the value of the current character
// and the next character.
current = GetValueOfChar(romanNum[i], i);
next = GetValueOfChar(romanNum[i+1], i+1);
// Compares the two values. If the next one is bigger,
// the current character is subtracted from 'decimal'.
if(next > current)
decimal -= current;
else
decimal += current;
}
return decimal;
}
int GetValueOfChar(char valRomNum[], int v)
{
int romanNumVal;
switch(valRomNum[v]){
case'M':
romanNumVal = VALUE_M;
break;
case'D':
romanNumVal = VALUE_D;
break;
case'C':
romanNumVal = VALUE_C;
break;
case'L':
romanNumVal = VALUE_L;
break;
case'X':
romanNumVal = VALUE_X;
break;
case'V':
romanNumVal = VALUE_V;
break;
case'I':
romanNumVal = VALUE_I;
break;
}
return romanNumVal;
}
void PrintDecimal(int theDecimal)
{
cout << "The value in decimal form is " << theDecimal << "\n\n";
}
I'm not really sure what the problem is, or how to fix it. Any help is appreciated!
Thank you very much! That got rid of that error. Although, now it`s saying:
[Linker error] undefined reference to `GetValueOfChar(char, int)'
[Linker error] undefined reference to `GetValueOfChar(char, int)'
ld returned 1 exit status
I did some research and apparently this doesnt mean that something is wrong with my code. I`m using Dev C++ btw, and I tried compiling it in Code::Blocks, but it says the same thing.
EDIT: Alright, I figured it out! Thanks for your help LowestOne.