> for (code[1] = code2[1];
Perhaps you could post something which actually compiles.
Then post something which is reasonably indented.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
6.8.5 Iteration statements
Syntax
iteration-statement:
while ( expression ) statement
do statement while ( expression ) ;
for ( expressionopt ; expressionopt ; expressionopt ) statement
for ( declaration expressionopt ; expressionopt ) statement
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
6.8.5 Iteration statements
Syntax
iteration-statement:
while ( expression ) statement
do statement while ( expression ) ;
for ( expressionopt ; expressionopt ; expressionopt ) statement
for ( declaration expressionopt ; expressionopt ) statement
According to the C++ standard it's:
6.5 Iteration Statements
iteration-statement:
while ( condition ) statement
do statement while ( expression ) ;
for ( for-init-statement conditionopt ; expressionopt ) statement
for-init-statement:
expression-statement
simple-declaration
[ Note: a for-init-statement ends with a semicolon. —end note ]
tux4life
Nearly a Posting Maven
2,350 posts since Feb 2009
Reputation Points: 2,134
Solved Threads: 243
I am having a problem with is matching up my array with the string. I am trying to use "array == string", because = is out of the question. I know I want it to say "is equal to", but that reads as a compilation error. Do you know what the correct operator would be?
Could you give us an example of the code you're trying to do this in?
(post the code where you have this problem with)
tux4life
Nearly a Posting Maven
2,350 posts since Feb 2009
Reputation Points: 2,134
Solved Threads: 243
You cannot compare a string directly with an integer, please take a look at the following example:
string s="1a3";
int arr[]={1,2,3};
for(int i=0; i<sizeof(arr)/sizeof(int); i++)
{
if((s[i]-'0')==arr[i])
cout << "equal" << endl;
else
cout << "not equal" << endl;
}
output will be:
equal
not equal
equal
tux4life
Nearly a Posting Maven
2,350 posts since Feb 2009
Reputation Points: 2,134
Solved Threads: 243
I understand that. That isn't something I can impliment into the code I was hoping for. If there isn't a way to direction compare/match an int to a char; is there a way to do what I overall want? Maybe, once the console input occurs, "1 2 3" or such it can look into my string and retrieve what "is equal to" those digits? Or visa versa, " a b c", get those equivelent in the int array? Maybe using a "cin.get()", to find the proper string or int.
I appreciate all your help so far, I would have ben fighting with that for a long time.
The example I provided demonstrates how you could implement it ...
The one I provided was for digits, sorry my mistake, but you can adapt it so you can also compare a whole integer to a string :)
tux4life
Nearly a Posting Maven
2,350 posts since Feb 2009
Reputation Points: 2,134
Solved Threads: 243
No, wait!!
I found a better option: convert the integer to a string using stringstreams and compare those two strings :)
int a = 50341;
stringstream ss;
string s, t("50341");
ss << a; // put the number in the stream
ss >> s; // take the number as a string out the stream
if(s==t) cout << "The integer's value is equal to the string's value." << endl;
don't forget to include sstream !
tux4life
Nearly a Posting Maven
2,350 posts since Feb 2009
Reputation Points: 2,134
Solved Threads: 243
>I am pretty sure it is going to take me a while because I am not sure what every statement there does.
What lines of my code don't you understand?
tux4life
Nearly a Posting Maven
2,350 posts since Feb 2009
Reputation Points: 2,134
Solved Threads: 243
int a = 50341; //declare const a=50341
Not sure why I need to create a const.
Can you refer me to the place where I mentioned that?
I don't think so as I didn't say you had to declare it as a const :P
BTW, post using code tags.
tux4life
Nearly a Posting Maven
2,350 posts since Feb 2009
Reputation Points: 2,134
Solved Threads: 243