Hey all,
I'm currently writing a calculator program for Uni which takes in 2 Roman Numeral expressions and displays the answer Roman Numerals. The answer is then displayed in Roman Numerals
i.e IX+XV = XXIV
The problem i'm having is trying to return an array from a function. The function takes in the integer answer worked out earlier in the program, and then converts this to roman numerals, saving each character in an array, which is created by the function. I wish to return the array back into the main program but i'm having problems
Sorry if this has been asked before, I tried searching the forums but couldn't find anything that similar .
The code for my sub-routine is as follows:
char convert(int answer)
{
int j=0;
char numeral[20];
// Calculate M's
while((answer-1000)>=0)
{
answer=answer-1000;
numeral[j++]='M';
}
if(answer>=900)
{
numeral[j++]='C';
numeral[j++]='M';
answer=answer-900;
}
// Calculate D's
while((answer-500)>=0)
{
answer=answer-500;
numeral[j]='D';
j++;
}
if(answer>=400)
{
numeral[j++]='C';
numeral[j++]='D';
answer=answer-400;
}
// Calculate C's
while((answer-100)>=0)
{
answer=answer-100;
numeral[j++]='C';
}
if(answer>=90)
{
numeral[j++]='X';
numeral[j++]='C';
answer=answer-90;
}
//Calcalute L's
while((answer-50)>=0)
{
answer=answer-50;
numeral[j++]='L';
}
if(answer>=40)
{
numeral[j++]='X';
numeral[j++]='L';
answer=answer-40;
}
// Calculate X's
while((answer-10)>=0)
{
answer=answer-10;
numeral[j++]='X';
}
if (answer==9)
{
numeral[j++]='I';
numeral[j++]='X';
answer=answer-9;
}
// Calculate V's
while((answer-5)>=0)
{
answer=answer-5;
numeral[j++]='V';
}
if(answer==4)
{
numeral[j++]='I';
numeral[j++]='V';
answer=answer-4;
}
// Calculate j's
while((answer-1)>=0)
{
answer=answer-1;
numeral[j++]='I';
}
numeral[j] = '\0';
printf("\n");
return numeral;
}
I want to return the array numeral so that it can be displayed on screen and the code can be used to convert other numbers.
These are the errors that the compiler is displaying:
Warn : roman.c(207,19)

uspicious pointer conversion
Error: roman.c(207,19):Nonportable pointer conversion
Can someone help me out so that i can get my program working properly?
Thanks in advance,
Dave
