这个课程是我刚刚参加的考试的一部分,我必须写.我只有这么远,无法到达任何地方.这是一个提示:"编写一个测试函数toDecimal(),将罗马数字(如MMLXVII)转换为十进制数表示.使用Main()测试函数.toDecimal()函数应该有2个参数,字符串数组为罗马数字和辅助函数.这个辅助函数将返回罗马数字中使用的每个字母的数值.然后将字符串参数转换为:查看前两个字符,如果第一个字符较大,则转换第一个字符和将它添加到求和中,然后使用第二个值再次调用转换函数并添加两者.如果第一个字符小于第二个字符,则从第二个字节中减去第一个字符,并将结果添加到字符串的转换中.也将转换字符串,如"IC".VLlidate字符串争论,如果有错误,调用错误处理函数.提供至少两个错误处理函数和测试toDecimal()与每个.一个可能是adking用户相关 ct,另一个可以纠正它."
I,X,C,M不能连续重复3次以上,D,L,V不能连续重复.我只能从V和X中减去,X只能从L和C中减去, C只能从D和M中减去.V,L和D永远不能减去.
我已经失去了大约2天的睡眠时间,尝试用数百种不同的方式使用和破坏规则.这是我最接近它的.
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <cstring>
using namespace std;
bool checker(string roman);
// Adds each value of the roman numeral together
int toDecimal(string, bool* (*function)(string));
int convert(string roman, int i);
int main(){
string roman;
cout << "This program takes a roman numeral the user enters then converts it to decimal notation." << endl;
cout << "Enter a roman numeral: ";
cin >> roman;
transform(roman.begin(), roman.end(), roman.begin(), toupper);
cout << roman << …Run Code Online (Sandbox Code Playgroud)