嘿,我認爲我很親密,但我不太確定如何繼續。所有與我的問題有關的問題都沒有真正回答。那我得到現在的錯誤是將羅馬數字轉換爲十進制
(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;
}
我很確定我走在正確的軌道上。很高興看到有關我的錯誤的任何提示或建議。
預先感謝
哪些是第33和第41行? – Barmar
順便說一下,問題在於編寫一個程序,將用羅馬數字輸入的數字轉換爲十進制。需要包含一個名爲romanType的類和一個執行以下操作的對象: 將編號存儲爲羅馬數字 將該編號轉換並存儲爲十進制形式 按用戶要求將該編號打印爲羅馬數字或十進制數 的羅馬數字的十進制值是: M = 1000 d = 500 C = 100 L = 50 X = 10 V = 5 I = 1 – user2726756
r.convertRoman(總);和r.printDecimal(total); – user2726756