Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #pragma warning (disable:4996)
- int main()
- {
- char num1, num2;
- int opchar;
- int ch1, ch2;
- int ans;
- int opOK;
- do{
- ch1 = ch2 = num1 = num2 = ans = 0;
- do{
- num1 = getchar();
- switch(num1)
- {
- case 'M':
- case 'm':
- ch1 += 1000;
- break;
- case 'D':
- case 'd':
- ch1 += 500;
- break;
- case 'C':
- case 'c':
- ch1 += 100;
- break;
- case 'L':
- case 'l':
- ch1 += 50;
- break;
- case 'X':
- case 'x':
- ch1 += 10;
- break;
- case 'V':
- case 'v':
- ch1 += 5;
- break;
- case 'I':
- case 'i':
- ch1 =+ 1;
- break;
- default:
- break;
- }
- }
- while(num1 != 'Q' && num1 !='q');
- do{
- num2 = getchar();
- switch(num2)
- {
- case 'M':
- case 'm':
- ch1 += 1000;
- break;
- case 'D':
- case 'd':
- ch1 += 500;
- break;
- case 'C':
- case 'c':
- ch1 += 100;
- break;
- case 'L':
- case 'l':
- ch1 += 50;
- break;
- case 'X':
- case 'x':
- ch1 += 10;
- break;
- case 'V':
- case 'v':
- ch1 += 5;
- break;
- case 'I':
- case 'i':
- ch1 =+ 1;
- break;
- default:
- break;
- }
- }
- while(num2 != 'Q' && num2 !='q');
- do{
- opchar = getchar();
- switch(opchar)
- {
- case '+':
- ans = ch1 + ch2;
- opOK = true;
- break;
- case '-':
- ans = ch1 - ch2;
- opOK = true;
- break;
- case '*':
- ans = ch1 * ch2;
- opOK = true;
- break;
- case '/':
- if(num2 ==0)
- {
- printf("\n-\n");
- opOK = false;
- break;
- }
- else
- {
- ans = ch1 / ch2;
- opOK = true;
- break;
- }
- defalut:
- printf("-\n");
- opOK = false;
- }
- }
- while(opOK != true);
- printf("\n%d\n", ans);
- if(ans < 0)
- {
- printf("-");
- ans *= -1;
- }
- while(ans >= 1000)
- {
- printf("M");
- ans -= 1000;
- }
- while(ans >= 500)
- {
- printf("D");
- ans -= 500;
- }
- while(ans >= 100)
- {
- printf("C");
- ans -= 100;
- }
- while(ans >= 50)
- {
- printf("L");
- ans -= 50;
- }
- while(ans >= 10)
- {
- printf("X");
- ans -= 10;
- }
- while(ans>= 5)
- {
- printf("V");
- ans -= 5;
- }
- while(ans >= 1)
- {
- printf("I");
- ans -= 1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement