You are here:

- Home
- Computing/Technology
- C/C++
- C++
- converting intergers into roman numerals and storing then into two parallel arrays

Advertisement

QUESTION: I am trying to write a program that lets a user enter a number and that number counts up 20 elements. The number is converted to roman and then they are stored into 2 parallel arrays one which holds only positive numbers and one which holds only strings. I have tried and tried to get this and I have made such a mess of the program that I was writing and I don't know how to fix it. I really don't know how to do the array thing. I think I can get the roman numeral part by looking at other things on the web but could you please help me get going. I don't even know where to start.

ANSWER: Hello,

Please, could you post your code here so I can see what you have done and know what to correct? Also, what do you mean by " that number counts up to 20 elements?" please, explain more and also post your code..

thanks

---------- FOLLOW-UP ----------

QUESTION: I sent in the one that I started over on but here is the one that I had so messed up maybe you can tell me which one I should try to use, if any:)Thank you so much for looking at this for me. I thought I had pretty well stayed caught up in until now. again thank you. I have like 4 programs open now trying to figure it out.

#include "stdafx.h"

#include <string>

#include <iomanip>

#include <iostream>

#include <cmath>

#include <cctype>

using namespace std;

void getRoman(int& roman);

const char{ M = 1000,D = 500,C = 100,L = 50,X = 10,V = 5, I = 1};

int _tmain( )

{

int n;

int Decimal;

string name = "Roman";

string roman[100];

int list[20];

char list[20];

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

cin >> n;

if((n >= 5000) || (n <=0))

{

cout << "Invalid Integer" << endl;

}

for( int n = 1; n <= 9999; n++)

{

cout << list[n] << " ";

}

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

if( n < 5000 )

{

roman = (n / 1000);

roman += 'M';

}

roman%= 1000;

if( n >= 100)

{

roman =(n / 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';

}

}

roman %= 100;

}

if ( n >= 10)

{

roman = (n / 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';

}

}

roman %= 10;

}

if( n >= 1)

{

roman = (n / 5);

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;

}

Hello,

I am sorry i am answering your question rather late. It is due to the fact that I am planning a marriage soon and I don't have all the leisure of sitting on the computer to answer questions aside my pay job but help me to help you.. kindly write a programme that converts an integer to romans and put it in a function and send me the function and I can try my best to complete the rest and also, explain details what you meant by the number counting up to 20 times, I asked this in the first instance... please, If I don't fully understand your aim , I will not be able to answer it :( so, do your best to put it clearly what you intend to achieve in the end and I will try to squeeze time to do it. I been getting replies from allexperts that I am late but bear with me, I got a lot on my plate right now :(

take care

Henry

I can confidently answer any question both basic and advanced in C++. Areas like templates, algorithms, Gui and design patterns are of interest to me. i will not answer questions about web programming.

I have a 3- year- work experience in software Engineering.**Education/Credentials**

I am a bachelor of Engineering graduate