Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <stdio.h>
- using namespace std;
- void egyes(int n)
- {
- if(n == 9) cout << "IX";
- else if(n == 4) cout << "IV";
- else
- {
- if(n >= 5) cout << "V";
- for(int i=1; i <= n % 5; i ++)
- {
- cout << "I";
- }
- }
- }
- void kettes(int n)
- {
- for(int i=1; i <= n/10; i++)
- {
- cout << "X";
- }
- egyes(n % 10);
- }
- void harmas(int n)
- {
- for(int i=1; i <= n/100; i++)
- {
- cout << "C";
- }
- n %= 100;
- if(n > 89)
- {
- cout << "XC";
- egyes(n - 90);
- }
- else if(n >= 50)
- {
- cout << "L";
- kettes(n - 50);
- }
- else if(n > 39)
- {
- cout << "XL";
- egyes(n - 40);
- }
- else
- {
- kettes(n);
- }
- }
- int main()
- {
- int n;
- setlocale(LC_ALL, "HUN");
- while(true)
- {
- cout << "\n\nKérek egy számot: ";
- cin >> n;
- if(n > 1001 || !isdigit(n))
- {
- cout << "Hibás a bemenet.";
- return 0;
- }
- if(n == 1000)
- {
- cout << "M";
- }
- else
- {
- if(n > 899)
- {
- cout << "CM";
- n -= 900;
- }
- else if(n >= 500)
- {
- cout << "D";
- n -= 500;
- }
- else if(n > 399)
- {
- cout << "CD";
- n -= 400;
- }
- harmas(n);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement