Lupercal
11-23-2005, 08:14 PM
I'm a first year university student who is taking a c++ programming class. In all honesty, I have no idea what I am doing, but I'm not here to ask you to tell me what to do.
We had the ever popular palindrome assignment given to us the other day, and I find myself stuck with truely understanding for loops, and how to use if statements without 'else'. I've been flagging in my program to see where I've gone wrong, however, I seem to think it's in my for loop that all hell has broken loose.
Here is the part where I seem to be stuck, and was wondering if anyone could explain to me (in general terms) the meaning behind the for loop. From my knowledge, my 'i' represents the first char in the string, while 'n' represents the last? Is this correct..?
for (int i = 0; i <n; i++)
{
if (s[i] != s[n-1]) //&& (s[i+1] != s[n-1-i]))
{
pal = false;
}
if ((s[i] == s[n-1]) && (s[i-1] == s[n-1-i]))
{
pal = true;
}
}
return pal;
:rolleyes:
We had the ever popular palindrome assignment given to us the other day, and I find myself stuck with truely understanding for loops, and how to use if statements without 'else'. I've been flagging in my program to see where I've gone wrong, however, I seem to think it's in my for loop that all hell has broken loose.
Here is the part where I seem to be stuck, and was wondering if anyone could explain to me (in general terms) the meaning behind the for loop. From my knowledge, my 'i' represents the first char in the string, while 'n' represents the last? Is this correct..?
for (int i = 0; i <n; i++)
{
if (s[i] != s[n-1]) //&& (s[i+1] != s[n-1-i]))
{
pal = false;
}
if ((s[i] == s[n-1]) && (s[i-1] == s[n-1-i]))
{
pal = true;
}
}
return pal;
:rolleyes: