Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This last if statement needs some modification. I can\'t find the right number f

ID: 3788142 • Letter: T

Question

This last if statement needs some modification. I can't find the right number for the "decimal -=" part:

#include <iostream>

using namespace std;

class romanType

{

public:

romanType();

romanType(string s);

~romanType();

void setRoman(string);

int romanToInteger();

void printNumber();

void printRoman();

  

private:

string romanNum;

int decimal = 0;

  

};

int main()

{

string numerals;

  

cout << "Enter Roman Numerals ONLY: ";

cin >> numerals;

  

romanType Rom;

Rom.setRoman(numerals);

Rom.romanToInteger();

cin.get();cin.get();

return 0;

  

}

romanType::romanType()

{

romanNum = 1;

}

romanType::~romanType()

{

}

void romanType::setRoman(string troll)

{

romanNum = troll;

}

int romanType::romanToInteger()

{

  

for (int i = 0; i < romanNum.length(); i++)

{

if (romanNum[i] == 'I') //good

decimal++;

  

if (romanNum[i] == 'V') //good

{

  

if (i > 0 && romanNum[i - 1] == 'I')

  

decimal -= 2;

decimal += 5;

}

  

if (romanNum[i] == 'X') //good

{

  

if (i > 0 && romanNum[i - 1] == 'I')

  

decimal -= 2;

decimal += 10;

}

  

if (romanNum[i] == 'L') //good

{

  

if (i > 0 && romanNum[i - 1] == 'X')

  

decimal -= 20;

decimal += 50;

}

  

if (romanNum[i] == 'C') //good

{

if (i > 0 && romanNum[i - 1] == 'X')

  

decimal -= 20;

decimal += 100;

}

  

if (romanNum[i] == 'D') //good

{

if (i > 0 && romanNum[i - 1] == 'C')

  

decimal -= 200;

decimal += 500;

}

  

if (romanNum[i] == 'M') //needs work

{

if (i < 0 && romanNum[i - 1] == 'C')

  

decimal -= 100;

decimal+= 1000;

}

}

  

cout << "Equivalent decimal is: " << decimal << endl;

  

return decimal;

  

}

Explanation / Answer

if (romanNum[i] == 'M') //needs work

{

if (i < 0 && romanNum[i - 1] == 'D')

  

decimal -= 1000;

decimal+= 1000;

}

}

  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote