1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
#include <iostream>
#include <climits>
#include <cctype>
using namespace std;
int main(void) //makes all values void until entered
{
system("color 0C");
while(true)
{
unsigned int Anum, divThousand, divHundred, divTen, divOne, //unsigned int keeps values unsigned until cin
modThousand, modHundred, modTen, modOne;
char RThousand; char RHundred; char RTen; char ROne;
int I = 1;
int IV = 4;
int V = 5;
int IX = 9;
int X = 10;
int L = 50;
int C = 100;
int D = 500;
int M = 1000;
RThousand = M;
RHundred = C;
RTen = X;
ROne = I;
//Arabic number, divide by 1000, divide by 100, divide by 10,
//divide by 1, take remainder of 1000, " " 100, " " 10, " " 1,
//Roman numeral thousands, " " hundreds, " " tens, " " ones
cout <<"\t\tHello, today you can convert Arabic Numerals to Roman Numerals\n";
cout <<"\n\nPlease enter the number you would like to convert\n";
cin >> Anum;
divThousand = Anum / 1000; //gets number to be reduced to just the first values of the digit place
modThousand = Anum % 1000;
divHundred = modThousand / 100;
modHundred = modThousand % 100;
divTen = modHundred / 10;
modTen = modHundred % 10;
divOne = modTen / 1;
modOne = modTen % 1;
RThousand = M * divThousand; //calculates the digits
RHundred = C * divHundred;
RTen = X * divTen;
ROne = I * divOne;
cout <<""<<RThousand<<", "<<RHundred<<", "<<RTen<<", "<<ROne<<"\n\n"; //outputs the digits in R.N.
int repeat = 0; //repeats program
while(repeat == 0)
{
char YesNo;
cout<< "Would you like to run the program again? (y/n): ";
cin>>YesNo;
switch (YesNo)
{
case 'Y': case 'y':
repeat = 1;
system ("cls");
break;
case 'N': case 'n':
return 0;
default:
cout<< "Invalid answer." <<endl;
cin.get();
break;
}
}
}
}
|