converting Roman numerals into decimal

4.7k views Asked by At

Hey guys I think I'm really close with but I'm not too sure how to continue. All of the questions related to my problem don't really answer anything. The error that I'm getting right now is an

(33): error C2064: term does not evaluate to a function taking 1 arguments
(41): error C2064: term does not evaluate to a function taking 1 arguments

Header file:

using namespace std;

class romanType
{
public: 
    void printRoman(char romanNum);
    int printDecimal(int& total);
    int convertRoman(int& total);
    void setRoman(char& roman);

    romanType();
    romanType(char);

private:
    char romanNum[6];
    int decimal;
    int total;
};

Implementation:

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include "romanType.h" 

using namespace std;

romanType::romanType(char)
{

};
void romanType::printRoman(char romanNum)
{
    cout << "Here is your number in Roman Numeral form: " << romanNum << endl;
};

int romanType::printDecimal(int& total)
{
    cout << "Here is your number in Decimal form: " << total << endl;
    return total;
};

void romanType::setRoman(char& romanNum)
{

};
int romanType::convertRoman(int& total)
{
    int len = 0;
    len = strlen(romanNum);
    int count[1];

     for(int i = 0; i < len; i++)
     {           
           switch(romanNum[i])
           {
                 case 'M':
                      count[i] = 1000;
                      break;
                 case 'm':
                      count[i] = 1000;
                      break;
                 case 'D':
                      count[i] = 500;
                      break;
                 case 'd':
                      count[i] = 500;
                      break;
                 case 'C':
                      count[i] = 100;
                      break;
                 case 'c':
                      count[i] = 100;
                      break;
                 case 'L':
                      count[i] = 50;
                      break;
                 case 'l':
                      count[i] = 50;
                      break;
                 case 'X':
                      count[i] = 10;
                      break;
                 case 'x':
                      count[i] = 10;
                      break;
                 case 'V':
                      count[i] = 5;
                      break;
                 case 'v':
                      count[i] = 5;
                      break;
                 case 'I':
                      count[i] = 1;
                      break;
                 case 'i':
                      count[i] = 1;
                      break;
                 default:
                      cout << "Error.." << endl;
           }   
           total = total + count[0];
     }
     return total;
};

My main:

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include "romanType.h"

using namespace std;

int main()
{
    romanType r;

    char romanNum;
    char choice;
    int decimal;
    int total;

    cout << "Hello! Please enter your Roman Numeral: " << endl; 
    cin >> romanNum; 
    cout << endl;


    r.setRoman(romanNum);
    r.convertRoman(total);

    cout << "Do you want the Roman Numeral or the Decimal?" << endl;
    cout << "Press [D] for Decimal!" << endl << "Press [R] for Roman Numeral!" << endl;

    cin >> choice;

    if (choice == 'D' || choice == 'd')
         r.printDecimal(total);
    else if (choice == 'R' || choice == 'r')
         r.printRoman(romanNum);
    else
        cout << "That wasn't the right button!" << endl;

    system ("pause");
    return 0;
}

I'm pretty sure I'm on the right track. It would be nice to see any tips or advice relating to my errors.

Thanks in advance

1

There are 1 answers

1
Brandon Z On

From just a quick look at the code, I might suggest looking through the debug window at the values of your variables at each step. What I am seeing is two variables, one char type named romanNum, and an entirely different one that is a char array named romanNum. It gets a little confusing but could work if you are only asking the user for a single char in roman numerals which then you wouldn't need an array at all. Otherwise, you could get a string then convert that into an array.

Start there and see if that helps.