446,234 Members | 1,872 Online
Need help? Post your question and get tips & solutions from a community of 446,234 IT Pros & Developers. It's quick & easy.

# Problem With Integers and Strings

 100+ P: 105 First of all, thank you in advance for your help and time. As for my problem, what it is is this: I have an integer and a string (I'll create a sample program below) and what I need to do is a number is added on to a string ever time it goes around a loop. Every time that number corrisponds with another number in the loop, a letter is added to a seaperate string and every time that happens, the string is reset to equal notheing. Idealy. I will give an example below. If you decide to give me examples, please use the variables that I use, because I'm new at this and it get very confusing some times. Thanks. Expand|Select|Wrap|Line Numbers #include  #include  #include  #include  #include  #include  #include  using namespace std; int main() //Variables int position; string original; string letter; string temp; int a; int b; string string; //Variables //Declarations position = 0; original = "0123456789"; //value of letter is decided below //value of temp is decided below a = 01234; b = 56789; //value of string is decided below //Declarations while (position != length) { letter = original[position]; if (temp == a) { string = string + "a"; temp = ""; } else if (temp == b) { string = string + "b"; temp = "";   } position = position + 1; } system("PAUSE"); return 0; }   Please remember that that is only a snippet of my code. Also: Operating System:Windows XP (SP2) C++ Compiler : DEV-C++--4.9.9.2 Mar 22 '07 #1
5 Replies

 P: 99 what, exactly, is the problem youre having? i mean, code snippets: great. descriptions: better. description of exactly where you need help: crucial. (its possible you removed just a little too much information when you gave just a portion of your code.) Mar 22 '07 #2

 100+ P: 105 what, exactly, is the problem youre having? i mean, code snippets: great. descriptions: better. description of exactly where you need help: crucial. (its possible you removed just a little too much information when you gave just a portion of your code.) I said what I was trying to do...In a way. Well..I at least implied it. What i want to do is take a long string of nubers and convert them into their corrisponding character on this side. The rest of the information on my first post should cover the rest of the gaps, but that was basically an overview. Mar 22 '07 #3

 100+ P: 105 I said what I was trying to do...In a way. Well..I at least implied it. What i want to do is take a long string of nubers and convert them into their corrisponding character on this side. The rest of the information on my first post should cover the rest of the gaps, but that was basically an overview. and about what i needed help on: right. well, When I try the code shown below, it dosn't work because of that I'm trying to transfer intigers and strings together. Try running the code. Mar 22 '07 #4

 P: 99 and whenever you use a string, you need to have a name for the string instead of using the type identifier "string". for example: Expand|Select|Wrap|Line Numbers if (temp == a) { string = string + "a"; //this will give an error because you cant declare a string with the name = string + "a" temp = ""; } otherwise, string concatenation should work like you think it does: as long as one of the operands is a string, the other can be char or char[] and the result is a string of the two operands concatenated. you can add a number (character version) to the string . . . if you need to cast the string to a number, thats a slightly different solution. Mar 22 '07 #5

 100+ P: 105 and whenever you use a string, you need to have a name for the string instead of using the type identifier "string". for example: Expand|Select|Wrap|Line Numbers if (temp == a) { string = string + "a"; //this will give an error because you cant declare a string with the name = string + "a" temp = ""; } otherwise, string concatenation should work like you think it does: as long as one of the operands is a string, the other can be char or char[] and the result is a string of the two operands concatenated. you can add a number (character version) to the string . . . if you need to cast the string to a number, thats a slightly different solution. The code Down Their Was Just An Example, but thank you for that knolage, it may come in handy. But the issue has been resolved. Thanks to everyone, without this forum, I don't know what I'd do ;) Mar 23 '07 #6