Aoami
I am a FH squatter
- Joined
- Dec 22, 2003
- Messages
- 11,223
Code:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
void UserConvert();
void BatchConvert();
void BatchConvert()
{
int arabicnum[30];
int arabicnumdoc[30];
int arabicnumdocout[30];
int counter;
char roman;
FILE *file_in;
FILE *file_out;
printf("Please enter the name of the file containing the list of Arabic Numbers to be converted: \n");
scanf("%s", &arabicnumdoc);
{
file_in=fopen("arabicnumdoc.txt", "r");
while (!feof(file_in))
{
fscanf(file_in, "%s", &arabicnum);
}
fclose(file_in);
}
roman =0;
for (counter =0; counter <29; counter++)
{
if(arabicnum[counter]==1)
roman +='I';
else if(arabicnum[counter -1]==5)
{
if(arabicnum[counter]==1)
roman +='I'+'I'+'I';
else
roman +='V';
}
if(arabicnum[counter]==10)
{
if(arabicnum[counter -1]==1)
roman +='V'+'I'+'I'+'I';
else if(arabicnum[counter]==5)
roman +=0;
else
roman +='X';
}
if(arabicnum[counter]==50)
{
if(arabicnum[counter -1]==1)
roman +='X'+'L'+'V'+'I'+'I'+'I';
else if(arabicnum[counter]==5)
roman +='X'+'L';
else if(arabicnum[counter]==10)
roman +='X'+'X'+'X';
else
roman +='L';
}
if(arabicnum[counter]==100)
{
if(arabicnum[counter -1]==1)
roman +='X'+'C'+'V'+'I'+'I'+'I';
else if(arabicnum[counter]==5)
roman +='X'+'C';
else if(arabicnum[counter]==10)
roman +='L'+'X'+'X'+'X';
else if(arabicnum[counter]==50)
roman +=0;
else
roman +='C';
}
if(arabicnum[counter]==500)
{
if(arabicnum[counter -1]==1)
roman +='C'+'D'+'X'+'C'+'V'+'I'+'I'+'I';
else if(arabicnum[counter]==5)
roman +='C'+'D'+'X'+'C';
else if(arabicnum[counter]==10)
roman +='C'+'D'+'L'+'X'+'X'+'X';
else if(arabicnum[counter]==50)
roman +='C'+'D';
else if(arabicnum[counter]==100)
roman +='C'+'C'+'C';
else
roman +='D';
}
if(arabicnum[counter]==1000)
{
if(arabicnum[counter -1]==1)
roman +='C'+'M'+'X'+'C'+'V'+'I'+'I'+'I';
else if(arabicnum[counter]==5)
roman +='C'+'M'+'X'+'C';
else if(arabicnum[counter]==10)
roman +='C'+'M'+'L'+'X'+'X'+'X';
else if(arabicnum[counter]==50)
roman +='C'+'M';
else if(arabicnum[counter]==100)
roman +='D'+'C'+'C'+'C';
else if(arabicnum[counter]==500)
roman +=0;
else
roman +='M';
}
}
{
printf("Please wait whilst the Arabic Numbers are converted \n\n");
printf("Please enter the name of the file to which the Roman Numerals will be written to: \n");
scanf("%s", &arabicnumdocout);
file_out=fopen("arabicnumdocout.txt", "w");
fprintf(file_out, "%d\n", roman);
fclose(file_out);
}
printf("The conversion is now complete, thank you for using my program\n\n");
}
void UserConvert()
{
int arabicnum[4];
int counter;
char roman;
printf("You have chosen to input the Arabic Number you wish to convert yourself. Please enter an Arabic Number: \n");
scanf("%d", &arabicnum);
roman ='I';
for (counter =0; counter <4; counter++)
{
if(arabicnum[counter]==1)
roman +='I';
else if(arabicnum[counter -1]==5)
{
if(arabicnum[counter]==1)
roman +='I'+'I'+'I';
else
roman +='V';
}
if(arabicnum[counter]==10)
{
if(arabicnum[counter -1]==1)
roman +='V'+'I'+'I'+'I';
else if(arabicnum[counter]==5)
roman +=0;
else
roman +='X';
}
if(arabicnum[counter]==50)
{
if(arabicnum[counter -1]==1)
roman +='X'+'L'+'V'+'I'+'I'+'I';
else if(arabicnum[counter]==5)
roman +='X'+'L';
else if(arabicnum[counter]==10)
roman +='X'+'X'+'X';
else
roman +='L';
}
if(arabicnum[counter]==100)
{
if(arabicnum[counter -1]==1)
roman +='X'+'C'+'V'+'I'+'I'+'I';
else if(arabicnum[counter]==5)
roman +='X'+'C';
else if(arabicnum[counter]==10)
roman +='L'+'X'+'X'+'X';
else if(arabicnum[counter]==50)
roman +=0;
else
roman +='C';
}
if(arabicnum[counter]==500)
{
if(arabicnum[counter -1]==1)
roman +='C'+'D'+'X'+'C'+'V'+'I'+'I'+'I';
else if(arabicnum[counter]==5)
roman +='C'+'D'+'X'+'C';
else if(arabicnum[counter]==10)
roman +='C'+'D'+'L'+'X'+'X'+'X';
else if(arabicnum[counter]==50)
roman +='C'+'D';
else if(arabicnum[counter]==100)
roman +='C'+'C'+'C';
else
roman +='D';
}
if(arabicnum[counter]==1000)
{
if(arabicnum[counter -1]==1)
roman +='C'+'M'+'X'+'C'+'V'+'I'+'I'+'I';
else if(arabicnum[counter]==5)
roman +='C'+'M'+'X'+'C';
else if(arabicnum[counter]==10)
roman +='C'+'M'+'L'+'X'+'X'+'X';
else if(arabicnum[counter]==50)
roman +='C'+'M';
else if(arabicnum[counter]==100)
roman +='D'+'C'+'C'+'C';
else if(arabicnum[counter]==500)
roman +=0;
else
roman +='M';
}
}
printf("The Arabic Number you entered was %d. The Roman equivelant is %c. \n\n", arabicnum, roman);
}
//everything from here on is the part of the program the user will see. A prompt appears asking the user to choose
//between inputting numbers themselves, or running batch mode.
void main()
{
int userchoice;
do
{
printf("Welcome to the numeral conversion program. Please press 1 to enter the Arabic Number you wish to convert, or 2 to convert a list of numbers: \n");
scanf("%d", &userchoice);
}
while ((userchoice != 1) && (userchoice != 2));
if (userchoice == 1)
UserConvert();
else if (userchoice == 2)
BatchConvert();
else;
}
Okay. I have to write a program to convert Arabic numbers (normal numbers) to Roman Numerals. Unfortunately, i'm a tard and wrote a program to convert Roman to Arabic. Basically i've tried to swap everything over. The first function is for a 'Batch' method, where it reads in a list of numbers from a txt doc, and writes the converted numbers into another. The second function is for the user to input a number into the cmd and it converts it there.
The program compiles, but gives me warnings about converting from int to char, which i'm not massively worried about, unless it's what has stopped the program working.
I've not tried the batch part yet, but when i enter a number into CMD is gives me the reply 'The Arabic Number you entered was 1244788. The Roman equivelant is random symbol'.
Have i got this completely wrong or is it something easy to fix?
Thanks in advance.