too long for pm...here it is then.....
Code:
#include <stdio.h>
#include <ctype.h>
#include <conio.h> /*for getch() fn */
int main(void)
{
int answer = 0;
char num1;
int tmp1 = 0;
char num2;
int tmp2 = 0;
printf("\nInput your first Roman Numeral (1 @ a time; # to quit) ");
/*NOTICE use of getch as defined in conio.h*/
while((num1 = getch()) != '#'){
switch( toupper( num1 ) ){
case 'I':
tmp1 = tmp1 + 1;
printf("\nInput your first Roman Numeral (1 @ a time; # to quit) ");
break;
case 'V':
tmp1 = tmp1 + 5;
printf("\nInput your first Roman Numeral (1 @ a time; # to quit) ");
break;
case 'X':
tmp1 = tmp1 + 10;
printf("\nInput your first Roman Numeral (1 @ a time; # to quit) ");
break;
case 'L':
tmp1 = tmp1 + 50;
printf("\nInput your first Roman Numeral (1 @ a time; # to quit) ");
break;
case 'C':
tmp1 = tmp1 + 100;
printf("\nInput your first Roman Numeral (1 @ a time; # to quit) ");
break;
case 'D':
tmp1 = tmp1 + 500;
printf("\nInput your first Roman Numeral (1 @ a time; # to quit) ");
break;
case 'M':
tmp1 = tmp1 + 1000;
printf("\nInput your first Roman Numeral (1 @ a time; # to quit) ");
break;
case '#':
printf("\nQuit then.");
break;
} // end switch
} // end while
/* NOTICE */
/*input of operation moved to after second roman input*/
printf("\nInput your second Roman Numeral (1 @ a time; # to quit) ");
/*NOTICE use of getch as defined in conio.h*/
while((num2 = getch()) != '#'){
switch( toupper( num2 ) ){
case 'I':
tmp2 = tmp2 + 1;
printf("\nInput your second Roman Numeral (1 @ a time; # to quit) ");
break;
case 'V':
tmp2 = tmp2 + 5;
printf("\nInput your second Roman Numeral (1 @ a time; # to quit) ");
break;
case 'X':
tmp2 = tmp2 + 10;
printf("\nInput your second Roman Numeral (1 @ a time; # to quit) ");
break;
case 'L':
tmp2 = tmp2 + 50;
printf("\nInput your second Roman Numeral (1 @ a time; # to quit) ");
break;
case 'C':
tmp2 = tmp2 + 100;
printf("\nInput your second Roman Numeral (1 @ a time; # to quit) ");
break;
case 'D':
tmp2 = tmp2 + 500;
printf("\nInput your second Roman Numeral (1 @ a time; # to quit) ");
break;
case 'M':
tmp2 = tmp2 + 1000;
printf("\nInput your second Roman Numeral (1 @ a time; # to quit) ");
break;
case '#':
printf("\nQuit then.");
printf("\nInput your second Roman Numeral (1 @ a time; # to quit) ");
break;
} //end switch
} //end while
/*NOTICE HERE is operation input */
printf("Enter mode of operation"
" A for add, S for subtract"
"M for multiply, D for divide");
/*NO NEED FOR oper TOUPPER AND GETCH fn take care*/
/*of user input*/
switch(toupper(getch()))
{
case 'A': answer = tmp1 + tmp2;/*now perform add */
break;
case 'S': answer = tmp1 - tmp2;/*perform subtract */
break;
case 'M': answer = tmp1 * tmp2;/*now multiply*/
break;
case 'D': answer = tmp1 / tmp2; /*finally divide*/
}
printf("\nYour answer is %d.",answer);
return 0;
}