Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Confused with operands in c++

Status
Not open for further replies.

Joesus

Programmer
Feb 6, 2002
1
US
I am pretty new to C++ and I am trying to write a program on my school's unix system that will change an integer value into Roman Numerals. I am fairly sure that my algorithm is ok. I use the cin command to get an integer, then using a do/while loop to take the integer and if it is 1000+ it will subtract 1000 from the beginning integer, and add an "M" to the string (I'm not sure if string is even a valid operand in C++, but i don't think a char is enough to show more than one letter). This continues until the nunber is no longer >=1000. Then to the 500's, 100's and so on, so that the number will be shown in Roman numeral form. I am not asking for anybody to write a program for me, just point me in the right direction. Any help would be greatly appreciated. Thank you in advance for your time and help.
Joe
 
Well,
first of all, indeed a char is not good enough, but
an array of chars is! In C++ a string is no more than an array of chars,but be careful,there are some rules,
Always put a '\0' for last character of your string,so C++ knows that the array stops;
e.g. char mystr[10];
strcpy(mystr,"Hello"); //strcpy puts the \0
automatically in the last pos
of your string

Your algoritm is ok,so to fill in a char on the right position,do it like this:
e.g. int i=3;
mystr='M';

in the previous example that would be:

cout<<mystr;

output: HelMo

Hope this helps! X-)




The Muppeteer.

themuppeteer@hotmail.com

Don't eat yellow snow...
 
Send me your algorythm, when done, please! I really need it in my current project. (Just remember, that 9=IX, not VIIII :) )
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top