Error: invalid conversion from `char*' to `char'

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'.

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
// Roman numeral to decimal converter

#include <cstdlib>
#include <iostream>

using namespace std;

const int VALUE_I = 1;
const int VALUE_V = 5;
const int VALUE_X = 10;
const int VALUE_L = 50;
const int VALUE_C = 100;
const int VALUE_D = 500;
const int 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!
Last edited on
You're passing converter a char* but it's declaration says it only takes a char.

int Converter(char*);

or you can continue with using the "[]", but you need to name the variable:
int Converter(char romanNum[]);
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.
Last edited on
Topic archived. No new replies allowed.