Int to String Conversion

Hello, I am programming a calculator for a class. The program takes in input in decimal, binary, trinary, hexadecimal, murnified, mayan, or positionless and converts them to ints to process commands. Then before they are printed out they are converted back to whichever system they need to be. My problem is with converting the ints back into strings of whichever type. Here is my code so far:

1
2
3
4
5
while(numToConvert > 10) {
		remainder = numToConvert % 10;
		numToConvert /= 10
		rv = rv + IntConversion(remainder)
	}


So I need to write the IntConversion function so it takes the remainder and returns a character I can concatenate onto the string until the whole number is built and the loop drops out. I can not use itoa or string streams, so how else can I convert and int? Thanks.
Last edited on
Ok so I have made some progress, here is my updated code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
string ConvertIntToDCMLString(CommandT & CommandFromFile) {
	string rv;
	int numToConvert = CommandFromFile.accum;
	cout << "NumToConvert: " << numToConvert << endl;
	int remainder = 0;
	
	while(numToConvert >= 10) {
		remainder = numToConvert % 10;
		numToConvert /= 10;
		rv = DCMLConversion(remainder) + rv;
	}
	
	return rv;
}


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
string DCMLConversion(int remainder) {
	string rv;
	
	if(remainder == 0)
		rv = "0";
	else if(remainder == 1)
		rv = "1";
	else if(remainder == 2)
		rv = "2";
	else if(remainder == 3)
		rv = "3";
	else if(remainder == 4)
		rv = "4";
	else if(remainder == 5)
		rv = "5";
	else if(remainder == 6)
		rv = "6";
	else if(remainder == 7)
		rv = "7";
	else if(remainder == 8)
		rv = "8";
	else if(remainder == 9)
		rv = "9";
	
	return rv;
}


Here is my output:
NumToConvert: 1653
653:DCML
NumToConvert: 1471
471:DCML
NumToConvert: 42809
2809:DCML
NumToConvert: 287
87:DCML


So everything is working now except the front digit is being chopped off everytime, anyone see my error?
Found my error. Needed to call DCMLConversion for numToConvert after the loop to get the last digit.
Topic archived. No new replies allowed.