将罗马数字转换为小数

时间:2013-08-28 19:25:37

标签: c++ decimal roman-numerals

嘿伙计们,我觉得我很亲近,但我不太清楚如何继续。所有与我的问题相关的问题都没有真正回答任何问题。我现在得到的错误是

(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

标题文件:

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;
};

实施:

#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;
};

我的主要内容:

#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;
}

我很确定我走在正确的轨道上。很高兴看到有关我的错误的任何提示或建议。

提前致谢

1 个答案:

答案 0 :(得分:-1)

从快速查看代码开始,我可能会建议在每个步骤中查看变量值的调试窗口。我看到的是两个变量,一个名为romanNum的char类型,一个名为romanNum的char数组完全不同的变量。它有点令人困惑,但如果你只是要求用户使用罗马数字中的单个字符,那么就可以工作了,那么你根本就不需要一个数组。否则,您可以获取一个字符串,然后将其转换为数组。

从那里开始,看看是否有帮助。

相关问题