Converting an Arabic Number to a Roman Numeral

Hello C++ Gurus, I need your aid once again. So far I have the "Menu" setup and now I just need to run a separate class that I created called romanType. I have the "Convert Arabic to Roman Numeral" currently setup (I hope the algorithm is correct) and I'm having trouble linking the menuDriver.cpp and romanType.cpp. Here is my code for all the parts (romanType.cpp, menuDriver.cpp, and romanType.h).

What need help with is that 1) It doesn't compile and 2) Let's say it does compile, it will loop back to the menuDriver after I enter an Arabic Number.

Thank you!

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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "stdafx.h"
#include "romanType.h"
#include <iostream>
#include <string>

using namespace std;


void DisplayMenu(); //Prototype DisplayMenu();

	/*	Function: Displays on the screen the selectin of addition, subtraction and exit.
		Precondition: None
		Postcondition: Menu will display listing 7 choices.
	*/

int GetCommand(int menuChoice); //Prototype GetCommand();

	/*	Function: Gets the choice from menu
		Preconditon: The user understands the choices the menu has to offer
		Postcondition: The user's choice is stored into menuChoice
	*/

void RunChoice(int menuChoice); //Prototype RunChoice();

	/*	Function: Run the command the user selected.
		Precondition: The user has selected a option that is stored in menuChoice
		Postcondition: The chosen option is ran based on the option that the user selected
	*/

int _tmain(int argc, _TCHAR* argv[])
{
	int menuChoice = 0; //Variable that will hold the stored input data
	
	do //Will run program at least once and will exit when option 7 is selected
	{
		DisplayMenu(); //Calling the DisplayMenu(); to show the options
		
		menuChoice = GetCommand(menuChoice); //Retrieves the option the user inputed
		
		RunChoice(menuChoice); //Runs the option the user selected

		cout << endl;
	}
	while(menuChoice != 7); //Will loop program until option 7 is selected
}

void DisplayMenu() //Displays the Menu for the user to choose from
	{
		cout << "Please choose from one of the following: " << endl;
		cout << "1. Get Arabic Number" << endl;
		cout << "2. Get Roman Numeral" << endl;
		cout << "3. Convert from Arabic to Roman" << endl;
		cout << "4. Convert from Roman to Arabic" << endl;
		cout << "5. Print Arabic Number" << endl;
		cout << "6. Print Roman Numberal" << endl;
		cout << "7. Quit" << endl;
	}

int GetCommand(int menuChoice) //Retrieves the choice made by the user
	{
		cout << endl << "Please type in your choice: ";
		cin >> menuChoice; //Stores data into menuChoice

		return (menuChoice);
	}

void RunChoice(int menuChoice) //Runs the choice that the user has selected
	{
		if(menuChoice==1){ //run "Get Arabic Number"
		}
		else {
			if (menuChoice==2){ //run "Get Roman Numeral"
			}
			else {
				if (menuChoice==3){ //run "Convert from Arabic to Roman"
					int ArabicInt = 0;

					cout << "Please enter an Arabic number: " << endl;
					cin >> ArabicInt; 

					romanType::ConvertArabicToRoman();

				}
				else {
					if (menuChoice==4) { //run "Convert from Roman to Arabic"
					}
					else {
						if (menuChoice==5) { //run "Print Arabic Number"
						}
						else {
							if (menuChoice==6) { //run "Print Roman Numeral"
							}
							else {
								if (menuChoice==7) { //run "Quit"
								}
							}
						}
					}
				}
			}
		}
	}


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
#include "stdafx.h"
#include "romanType.h"
#include <iostream>
#include <cstring>
#include <string>

using namespace std;

romanType::romanType()
{	
}

void romanType:: GetArabicNumber(int num)
{
	RomanStr.clear();
	ArabicInt = num;
}

void romanType:: GetRomanNumeral(std::string str)
{
	RomanStr.clear();
	RomanStr = str;
	RomanStr += " ";
}

void romanType:: ConvertArabicToRoman()
{
	int h, th, t, o, num;
	char *ones[] = {"","I","II","III","IV","V","VI","VII","VIII","IX"};
	char *tens[] = {"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"};
	char *hundreds[] = {"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"};
	char *thousands[] = {"","M","MM","MMM","MMMM","MMMMM"};

	if (num <= 5000) 
	{
    th = num / 1000;
    num = num % 1000;  // get rid of the 1000s
 
    h = num % 100;
    num = num % 100;   // get rid of the 100s
 
    t = num / 10;
    o = num % 10;
    RomanStr = RomanStr + thousands[th] + hundreds[h] + tens[t] + ones[o];
	}
}

string romanType:: PrintRomanNumeral(){
	return(RomanStr);
}

int romanType:: PrintArabicNumber()
{
	return(ArabicInt);
}

romanType:: ~romanType()
{

}


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

#include <string>

class romanType
{
public:
	romanType();
		/*
		Function: Constructor function for the romanType class
		Precondition: None
		Postcondition: None
		*/
	void GetArabicNumber(int num);
		/*
		Function: Gets the Arabic Number from the user.
		Precondition: The menu driver is set up and working
		Postcondition: 
		*/
	void GetRomanNumeral(std::string str);
		/*
		Function: Gets the Roman Numeral from the user.
		Precondition: The menu driver is set up and working.
		Postcondition: 
		*/
	void ConvertArabicToRoman();
		/*
		Function: Converts the Arabic number to a Roman Numeral.
		Precondition:
		Postcondition:
		*/
	void ConvertRomanToArabic();
		/*
		Function: Converts the Roman Numeral to an Arabic number.
		Precondition:
		Postcondition:
		*/
	std::string PrintRomanNumeral();
		/*
		Function: Prints the Roman Numeral.
		Precondition:
		Postcondition:
		*/
	int PrintArabicNumber();
		/*
		Function: Prints the Arabic number.
		Precondition: 
		Postcondition:
		*/
	~romanType();
		/*
		Function: The deconstructor for romanType
		Precondition: None
		Postcondition: None
		*/
private:
	int ArabicInt;	//Stores the Arabic number
	std::string RomanStr;	//Stores the Roman Numeral
};
Topic archived. No new replies allowed.