Ironworks Gaming Forum

Ironworks Gaming Forum (http://www.ironworksforum.com/forum/index.php)
-   General Conversation Archives (11/2000 - 01/2005) (http://www.ironworksforum.com/forum/forumdisplay.php?f=28)
-   -   c++ question (http://www.ironworksforum.com/forum/showthread.php?t=82813)

Blade 11-21-2002 02:22 PM

I'm working on a c++ assignment and i need a little help. I have to compare two end slots in a char array and work my way in ex. first with last, second with second to last ect., then return wheather all the charecter match or not. I can't figure out how to exactly to do it. I know it has something to do with a loop and an if statement but how how exactly i can't figure out.

NiceWorg 11-21-2002 03:59 PM

Sorry, I have no clue, and I spam this just to promote Java. It makes everything so much easier.

Blade 11-21-2002 04:01 PM

don't know java, plus this is a c++ class so [img]tongue.gif[/img] its fun and not to hard just time consuming. Less now though that i'm using Visual Basic :D great program and you can use lots of languages in it.

andrewas 11-21-2002 04:06 PM

</font><blockquote>code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">for(n:=0,m:=len(str)-1;n&gt;m;n++,m--)
{
// your camparison goes in here
}</pre>[/QUOTE]Ye gods but I havent used this stuff in while. That for loop is fairly simple -initialise n and m to the beginning and end of your string, end the loop when n is more than m, each loop increment n and decrement m.

But I think youll need to check the logic, run through it (on paper) with odd and even length strings. And get a textbook and make sure that thats the correct syntax for a two-variable for loop, I havent used one in *years*. Easiest way to return the result is

</font><blockquote>code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">result:=true;
for(n:=0,m:=len(str)-1;n&gt;m;n++,m--)
{
if(str[n]!=str[m] then
result:=false;
}
return(result);</pre>[/QUOTE]Heh - as you can see Im confusing Pascal and C++ syntax. Trouble with switching languages so often [img]smile.gif[/img] Anyway, that bit is fairly standard logic. Only one fail is needed to fail the whole lot, so you may want to optimise with a break statement, but I woudnt bother outside of a performance critical function, which this isnt as its a homework problem.

WillowIX 11-21-2002 04:13 PM

Andrewas, you really ought to add something like "Official computer expert of IW" or something in your signature! [img]graemlins/thumbsup.gif[/img] BTW andrewas, do you know if I can manually add the acrobat script to Word XP? The one that allows you to convert to PDF without changing printer properties? (I think it´s called acrobat.dot) [img]smile.gif[/img]

SirTristram 11-21-2002 08:16 PM

Is this an assignment to find out if a word is a palindrome? if it is, do NOT compare 1st to last, 2nd to 2nd last, etc. instead, reverse your original string and then compare the two...

Blade 11-22-2002 01:42 AM

well i allready did that for on funcition, we need to do it two different ways. Sorry for the late reply i have been of doing things. I'll give it a try andrewas

Blade 11-22-2002 02:02 AM

well here i would post my code here so people could confuse themselves but it says html code error, doesn't allow parenthasis on my :( o well thank for the help, it works. I knew it would just coudn't figure out how to put it into code thanks.

/)eathKiller 11-22-2002 02:10 AM

well you do know that Java and C++ are cousins...

Blade 11-22-2002 02:16 AM

there are lots of simular languages there Death, c++, java, and basicaly any general overall languages are related. They all take the code and encode it into the same basic language, that is how all the .net stuff works you know.


All times are GMT -4. The time now is 08:43 AM.

Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
©2024 Ironworks Gaming & ©2024 The Great Escape Studios TM - All Rights Reserved