I'm having trouble getting this program to work for roman numeral conversion. I hope it says that i have one error, which is C2110: cannot add two pointers. here's what i have so far... ANY help would be great, thanks a bunch! :)

#include <iostream>
using namespace std;

int main()
{
	//Type in an integer between 1 and 4000
	int numToConvert;
	cout << "Enter an integer between 1 and 4000";
	cin >> numToConvert;
	int th,h,t,o;
	char thousands[] = {"", "M", "MM", "MMM", "MMMM"};
	char hundreds[] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"};
	char tens[] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"};
	char ones[] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"};

	if (numToConvert<=4000){
		int romanNumber;
		th = numToConvert / 1000;
		numToConvert = numToConvert % 1000;
		h = numToConvert % 100;
		t = numToConvert / 10;
		o = numToConvert % 10;
		romanNumber = romanNumber + thousands[th] + hundreds[h] + tens[t] + ones[o];
		cout << "The roman number for this integer is " << romanNumber;
	}
	else
	{
		cout << "Invalid number, please enter a new number between 1 and 4000";
		return 0;
	}
}

I'm having trouble getting this program to work for roman numeral conversion. I hope it says that i have one error, which is C2110: cannot add two pointers. here's what i have so far... ANY help would be great

1) Use CODE Tags
2) Don't tell us you hope for an error, tell us exactly what error you get
3) Don't make us guess what line the error is on. Tell us. We aren't psychicprogrammers.com you know.

char thousands[] = {"", "M", "MM", "MMM", "MMMM"}; This is an error; thousands is an array of chars, not an array of c-style strings.
You need to do something like this instead. const char* thousands[] = {"", "M", "MM", "MMM", "MMMM"}; > i have one error, which is C2110: cannot add two pointers.

If you want to use the + operator to concatenate strings, use std::string instead of c-style string.

char a[100] = "abcd" ;
const char b[] = "ef" ;
a = a + b ; // *** error *** 

std::string c = "abcd" ;
c = c + b ; // fine

See: http://www.cprogramming.com/tutorial/string.html

Also, if you haven't discovered it yet, your conversion is broken starting at line 20. Take any starting number, say, 2937, and trace through that block of code by hand, and see what values it's going to get for the four index variables.

And romanNumber is declared as int at line 17. Definitely not the case. :)

Hmmm my programming teacher hasn't even taught what a string is... nor is it explained in my book. Not quite sure where to put the std::string function in my program, but i'll give it a whack. thanks for the feedback, and i'll post my program once i get it edited

Hey i figured it out. thanks for the help guys. :) cheers

Glad to hear it. Please mark the thread as "solved" for us. Thanks! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.