The last two FOR loops in the PRINT function in bold only ha

The last two FOR loops in the PRINT function in bold only have 2/3 of the elements needed in the (), tried to figure it out, but the bold is still not right:

// main.cpp

// Ch. 10 Programming II

//

// Created by Jordyn Hamilton on 1/26/17.

// Copyright © 2017 Jordyn Hamilton. All rights reserved.

//

#include <iostream>

#include <iomanip>

#include <string>

#include <cmath>

using namespace std;

class romanType

{

public:

  

void print(char[]);

void set();

  

private:

  

string romanInt[7];

};

int main()

{

romanType rome;

  

rome.set();

  

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

return 0;

}

void romanType::print(char RomanNumeral[8])

{

char romanInt[7] = {\'M\', \'D\', \'C\', \'L\', \'X\', \'V\', \'I\'};

  

int integerValue[7] = {1000, 500, 100, 50, 10, 5, 1};

  

int length, x, y, total;

  

int value[10];

  

for (int x = 0; x <= 7; x++)

{

if (RomanNumeral[x] != \'\\0\')

{

length++;

}

else

{

x = 7;

}

}

  

for (int x = 0; x <= 7; x++)

{

for (int y = 0; y < 7; y++)

{

if (RomanNumeral[x] == romanInt[y])

{

value[x] = integerValue[y];

}

  

}

}

  

for (int x = 0; x <= 7; x++)

{

if (value[x])

{

total += value[x+1] - value[x];

}

else

{

total += value[x];

}

  

cout << \"Equivalent integer value is: \" << total << endl;

}

}

void romanType::set()

{

char RomanNumeral[8];

  

int i;

  

cout << \"Please enter in Roman Numerals ONLY: \" << endl;

cin >> RomanNumeral;

  

for ( i =0; i < 8; i++)

{

RomanNumeral[i] = toupper(RomanNumeral[i]);

  

print(RomanNumeral);

}

}

Solution

#include <iostream>

#include <string>

using namespace std;

class romanType{

public:

    romanType();

    romanType(string s);

    ~romanType();

        void setRoman(string);

        int romanToDecimal();

        void printDecimal();

        void printRoman();

private:

    string romanNum;

    int decimalNum = 0;

};

romanType::romanType()

{

    romanNum = 1;

}

romanType::~romanType()

{

}

void romanType::setRoman(string troll)

{

    romanNum = troll;

}

int romanType::romanToDecimal()

{

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

    {

        if (romanNum[i] == \'I\')

            decimalNum++;

        if (romanNum[i] == \'V\')

        {

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

                decimalNum -= 2;

            decimalNum += 5;

        }

        if (romanNum[i] == \'X\')

        {

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

                decimalNum -= 2;

            decimalNum += 10;

        }

        if (romanNum[i] == \'L\')

        {

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

                decimalNum -= 20;

            decimalNum += 50;

        }

    }

    cout << decimalNum << endl;

    return decimalNum;

}

int main()

{

    string numerals;

    do{

        cout << \"Enter roman numerals: \";

        cin >> numerals;

        romanType Rom;

        Rom.setRoman(numerals);

        Rom.romanToDecimal();

    } while (true);

    system(\"PAUSE\");

}

//try this

The last two FOR loops in the PRINT function in bold only have 2/3 of the elements needed in the (), tried to figure it out, but the bold is still not right: //
The last two FOR loops in the PRINT function in bold only have 2/3 of the elements needed in the (), tried to figure it out, but the bold is still not right: //
The last two FOR loops in the PRINT function in bold only have 2/3 of the elements needed in the (), tried to figure it out, but the bold is still not right: //
The last two FOR loops in the PRINT function in bold only have 2/3 of the elements needed in the (), tried to figure it out, but the bold is still not right: //
The last two FOR loops in the PRINT function in bold only have 2/3 of the elements needed in the (), tried to figure it out, but the bold is still not right: //
The last two FOR loops in the PRINT function in bold only have 2/3 of the elements needed in the (), tried to figure it out, but the bold is still not right: //

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site