Просто хочу изменить свой вопрос на данный момент - я мог бы просто использовать некоторые рекомендации относительно того, почему у меня три ошибки компилятора в моей программе, не совсем уверен, что я сделал неправильно/am missing - я добавил комментарии в код, чтобы указать, где они находятся. БлагодаряНесколько ошибок - попытка конвертировать римскую запись в десятичный
#include <iostream>
#include <string>
using namespace std;
class romanType
{
public:
void setRomanNum(string store);
// this function will store the Roman numeral
int convertNum(char rNum);
// this function will convert the Roman numeral to a decimal
void decimalPrint(int total);
// this function will print the decimal number
void romanPrint(char rNum);
// this function will print the Roman numeral
int getNum(char letter);
// this function will get the number input
romanType(int store);
//Constructor with parameter
romanType();
char roman[7];
string num;
int length = 0;
string dNum;
int equals;
};
romanType::romanType(int store)
{
dNum = 1;
}
void romanType::setRomanNum (string store)
{
dNum = store;
}
void romanType::romanPrint(char rNum)
{
cout << "The Roman numeral is: " << roman << endl;
}
void romanType::decimalPrint(int total)
{
cout << "The Decimal number is: " << equals << endl;
}
int romanType::convertNum (char rNum)
{
int letter;
int totalNum = 0;
for (int i = 0; i< dNum.length(); i++)
// "loop will run at most once (loop increment never executed)"?
{
switch (roman[i])
{
case 'M':
totalNum+= 1000;
break;
case 'D':
totalNum += 500;
break;
case 'C':
totalNum += 100;
break;
case 'L':
totalNum += 50;
break;
case 'X':
totalNum += 10;
break;
case 'V':
totalNum += 5;
break;
case 'I':
totalNum += 1;
break;
}
totalNum = totalNum + letter;
equals = totalNum;
return equals;
}
};
// "control may reach end of non-void function"
int main()
{
romanType output;
int rNumeral;
char entry;
cout << "Please enter a Roman numeral (Capitalized only): " << endl;
cin >> rNumeral;
cout << "Print Decimal or Roman Numeral? Type 1 for Decimal, 2 for Roman Numeral: " << endl;
cin >> entry;
if (entry == '1')
{
cout << "You chose to view the decimal conversion." << endl;
output.decimalPrint(rNum);
// How do I output the decimal conversion from the void romanType::decimalPrint(int total) function?
}
else if (entry == '2')
{
cout << "You chose to view the Roman numeral." << endl;
output.romanPrint(rNumeral);
}
else
cout << "Error: bad input" << endl;
return 0;
exit(1);
}
один вопрос на каждый вопрос, пожалуйста. stackoverflow.com не является учебным пособием или службой отладки. Укажите конкретный, дискретный, убедительный вопрос, вместо того, чтобы просить всех искать случай, который случайно посыпал ваш код, как какая-то охота на пасхальные яйца. –
Исправить ошибки компилятора 1. Узнайте, как их читать. После того, как вы выполнили код с помощью отладчика, чтобы догнать логические ошибки. Вы не можете ожидать, что мы сделаем это для вас здесь. –
Исправлено несколько ошибок компилятора, я не знал, как их исправить - все еще есть пара. Если кто-то может помочь мне с ошибками компилятора, это было бы здорово. Я добавил пару комментариев, где я получаю ошибки и не понимаю, почему. Я могу спросить о логике в отдельном вопросе - просто подумал, что это запрещено. Сожалею. – Croset