473,326 Members | 2,128 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Problem With Integers and Strings

compman9902
105 100+
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
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5. #include <sstream>
  6. #include <string.h>
  7. #include <fstream>
  8. using namespace std;
  9. int main()
  10. //Variables
  11. int position;
  12. string original;
  13. string letter;
  14. string temp;
  15. int a;
  16. int b;
  17. string string;
  18. //Variables
  19. //Declarations
  20. position = 0;
  21. original = "0123456789";
  22. //value of letter is decided below
  23. //value of temp is decided below
  24. a = 01234;
  25. b = 56789;
  26. //value of string is decided below
  27. //Declarations
  28. while (position != length)
  29. {
  30. letter = original[position];
  31. if (temp == a)
  32. {
  33. string = string + "a";
  34. temp = "";
  35. }
  36. else if (temp == b)
  37. {
  38. string = string + "b";
  39. temp = "";  
  40. }
  41. position = position + 1;
  42. }
  43. system("PAUSE");
  44. return 0;
  45. }
  46.  
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 1417
Roonie
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
compman9902
105 100+
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
compman9902
105 100+
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
Roonie
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
  1. if (temp == a)
  2. {
  3. string = string + "a"; //this will give an error because you cant declare a string with the name = string + "a"
  4. temp = "";
  5. }
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
compman9902
105 100+
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
  1. if (temp == a)
  2. {
  3. string = string + "a"; //this will give an error because you cant declare a string with the name = string + "a"
  4. temp = "";
  5. }
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

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: beliavsky | last post by:
By mistake I coded something like print ("1" > 1) and got the result "True". Comparing an integer and a string seems meaningless to me, and I would prefer to have an exception thrown. Can...
6
by: Ulrich Vollenbruch | last post by:
Hi all! since I'am used to work with matlab for a long time and now have to work with c/c++, I have again some problems with the usage of strings, pointers and arrays. So please excuse my basic...
2
by: Pete | last post by:
Sorry for the ambiguity of my last post, What I am try to do is enter a 10 bit binary string eg: 1110001010 and then permute them into an array using an array containing 3,5,2,7,4,10,1,9,8,6 as...
6
by: comp.lang.php | last post by:
I'm involved in a rather nasty debate involving a strange issue (whereby the exasperated tell me to RTFM even after my having done so), where this is insanely possible: print_r(is_int('1'));...
27
by: John Salerno | last post by:
Ok, here's a problem I've sort of assigned to myself for fun, but it's turning out to be quite a pain to wrap my mind around. It's from a puzzle game. It will help if you look at this image: ...
5
by: Pradeep | last post by:
Hi All, I am facing some problem using istream_iterator for reading the contents of a file and copying it in a vector of strings.However the same thing works for a vector of integers. The...
8
by: BD | last post by:
Moving from MS Access to .Net using C# languag. Problem trying to duplicate form with structure as follows: 1. Main form 'Work Order' displayed as textboxes 2. subform 'Customers' textboxes...
6
by: gasfusion | last post by:
I wrote a class Min-Max Heap Template Class which works perfectly fine with integers. As part of this data structure, i have to implement some sort of method to check for the smallest...
3
by: Jeff | last post by:
....still new to vb.net 2005 I understand the concept of arrays, and have used them in other languages, but was hoping that someone could get me started with something. I have a fairly long...
6
by: efrenba | last post by:
Hi, I came from delphi world and now I'm doing my first steps in C++. I'm using C++builder because its ide is like delphi although I'm trying to avoid the vcl. I need to insert new features...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.