malcolmmatheson
02-28-2005, 03:27 PM
Could anyone help me create a roman calculator in C language. (Not C++).
The following is a simple calculator in decimal form. I need to converter that converts Roman to decimal, and then decimal back to roman after the calculation has been carried out. The user inputs a roman number, and then outputs a roman number. (Eg. IV + V = IX)
Thanks
#include <stdio.h>
int main( void ) {
int i, j, calculation;
char c;
printf("Enter your calculation using + - / *\n");
scanf("%d",&i);
scanf("%c",&c);
scanf("%d",&j);
switch ( c ) {
case'+':calculation = i + j; break;
case '-':calculation = i - j; break;
case '*':calculation = i * j; break;
case '/':if ( j == 0 ) printf("Error, cant divide by zero");
else {calculation = i / j;}
if (j>i)
printf("First number must be higher then second!");
{
default: printf("Not Accepted operator");break;
return 0;
}
}
if (j==0)
printf(".");
else{
printf("The result is: %d\n",calculation);
} }
Mod Edit: It's a good idea to take advantage of the vb [code] tags to maintain legibility. Take 'em for a spin. :)
The following is a simple calculator in decimal form. I need to converter that converts Roman to decimal, and then decimal back to roman after the calculation has been carried out. The user inputs a roman number, and then outputs a roman number. (Eg. IV + V = IX)
Thanks
#include <stdio.h>
int main( void ) {
int i, j, calculation;
char c;
printf("Enter your calculation using + - / *\n");
scanf("%d",&i);
scanf("%c",&c);
scanf("%d",&j);
switch ( c ) {
case'+':calculation = i + j; break;
case '-':calculation = i - j; break;
case '*':calculation = i * j; break;
case '/':if ( j == 0 ) printf("Error, cant divide by zero");
else {calculation = i / j;}
if (j>i)
printf("First number must be higher then second!");
{
default: printf("Not Accepted operator");break;
return 0;
}
}
if (j==0)
printf(".");
else{
printf("The result is: %d\n",calculation);
} }
Mod Edit: It's a good idea to take advantage of the vb [code] tags to maintain legibility. Take 'em for a spin. :)