1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Converting intergers into roman numerals and storing then into two parallel arrays

  1. Dec 1, 2012 #1
    I am trying to make a program that lets a user input a number(which counts up 20 elements) and that is converted into roman numerals. I need 2 parallel arrays, one which holds only positive numbers and one which holds only strings. I keep getting 2 error messages "+= int differs in levels of undirection from 'const char[2]'" and "+= illegal right operand has type 'const char[3]'". Any help would be very much appreciated.

    This is what I have so far.

    #include "stdafx.h"
    #include <string>
    #include <iomanip>
    #include <iostream>
    #include <cmath>

    using namespace std;

    void getRoman(int& roman);
    const char;
    enum romanType{ M = 1000,D = 500,C = 100,L = 50,X = 10,V = 5, I = 1};

    int _tmain( )
    {
    int n;

    int numeral;
    int Decimal;
    int roman;
    string list[20];

    cout << "Enter an integer from 1-5000" << endl;
    cin >> n;


    if((Decimal >= 5000) || (Decimal <=0))
    {
    cout << "Invalid Integer" << endl;
    }

    for (int row = 0; row < 20; row++)
    {
    list[row]=Decimal;
    list[row]=n;
    }

    for( int n = 1; n <= 9999; n++)
    {
    cout << list[n] << " "<< Decimal;
    }

    for(n = 1; n <= 5000; n++)


    if( n < 5000 )
    {
    roman = (n / 1000);
    roman += "M";
    }
    roman%= 1000;

    if( n >= 100)
    {
    roman =(Decimal / 100);
    if( roman ==9)
    {
    roman += "CM";
    }
    else if (roman >= 5)
    {
    roman += "D";

    for( int i = 0; i < roman-5; i++)
    {
    roman += "C";
    }
    }
    else if ( roman == 4)
    {
    roman += "CD";
    }
    else if (roman >1)
    {
    for( int i= 0; i < roman; i++)
    {
    roman += "C";
    }
    }
    Decimal %= 100;
    }
    if ( Decimal >= 10)
    {
    roman = (Decimal / 10);
    if ( roman ==9)
    {
    roman += "XC";
    }
    else if( roman >= 5)
    {
    roman += "L";
    for( int n = 0; n < roman-5; n++)
    {
    roman += "X";
    }
    }
    else if ( roman == 4)
    {
    roman += "XL";
    }
    else if ( roman >= 1)
    {
    for( int n = 0; n < roman; n++)
    {
    roman += "X";
    }
    }
    Decimal %= 10;
    }
    if( Decimal >= 1)
    {
    roman = Decimal;

    if( roman == 9)
    {
    roman += "IX";
    }
    else if( roman >=5)
    {
    roman += "V";
    for( int n = 0; n < roman-5;n++)
    {
    roman += "I";
    }
    }
    else if( roman ==4)
    {
    roman += "IV";
    }
    else if( roman >= 1)
    {
    for( int n = 0; n < roman; n++)
    {
    roman += "I";
    }
    }
    }


    system ("pause");
    return 0;
    }
     
  2. jcsd
  3. Dec 1, 2012 #2
    Re: converting intergers into roman numerals and storing then into two parallel array

    I figured that out but now I still have a problem with
    enum romanType{M=1000 and so on}
    I don't have something right but I cannot figure it out. I tried taking out "enum" but that made even more errors. Does someone know what I am doing wrong? please
     
  4. Dec 1, 2012 #3

    Mark44

    Staff: Mentor

    Re: converting intergers into roman numerals and storing then into two parallel array

    When you enter code, surround your code with a [ code ] tag at the top and a [ /code ] tag at the bottom (no spaces). This preserves your indentation and makes your code easier to read. I have done this in your code below.

    The first thing I noticed is that you used Decimal in the first if block before you gave it a value. You never want to do this, because it will have a garbage value.

    Looking through your code, I don't see Decimal getting a value anywhere, but you use its value in a lot of places. When you get past your compile errors to a program that runs, you are going to get garbage results because of this.

    The next thing I noticed was that you are trying to add a string value to an int variable.
    Code (Text):

    roman += "M";
     
    You have a lot of lines of code like this. This is very likely the source of at least some of your compile errors.

    Since roman is going to contain Roman numerals (i.e., characters), it should be declared as a string, not an int.

    Why do you have your romanType enumeration? It's not used anywhere. If it's not used, you should remove it.

     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Converting intergers into roman numerals and storing then into two parallel arrays
  1. Numerical Array split (Replies: 9)

Loading...