View Full Version : c++ help?
three.eighteen.
03-31-2003, 12:15 AM
im just starting to work with arrays...so say you have 10 numbers in the array...whats the easiest way to get the program to find the largest one? i cant seem to wrap my head around how to use an if (if i should even be using if) to find it...
Phats
03-31-2003, 12:20 AM
use a for statement, it will look like this
int temp = array[0];
for(int i=1; i<10;i++)
{
if(temp < array[i])
temp = array[i];
}
this way, you set the first number in the array to temp, then it will go through the array and if it finds a number in the array that is larger than the number in temp, it will assign the number to temp
edit: aahhh, my spacing didn't show up right, anyway, you should be able to get the idea
three.eighteen.
03-31-2003, 12:22 AM
oooh...damn...i miss assembly language lol
Phats
03-31-2003, 12:31 AM
haha, nice
roopi
03-31-2003, 02:38 AM
Originally posted by three.eighteen.
oooh...damn...i miss assembly language lol
if you miss it so much will you do my homework that is due on Tuesday?
I'm serious! :D
redec
03-31-2003, 09:45 AM
Originally posted by three.eighteen.
oooh...damn...i miss assembly language lol
wtf?....you're saying you could do this in asm but you can't figure out how to do it in C?
Originally posted by Phats
use a for statement, it will look like this
int temp = array[0];
for(int i=1; i<10;i++)
{
if(temp < array[i])
temp = array[i];
}
this way, you set the first number in the array to temp, then it will go through the array and if it finds a number in the array that is larger than the number in temp, it will assign the number to temp
edit: aahhh, my spacing didn't show up right, anyway, you should be able to get the idea
hahah...that looks like my flash action scripting shit.. lol
Phats
03-31-2003, 09:56 AM
ooohhhh, that sounds almost as fun as C++, actually, I do like coding C++, meh, I'm just a nerd at heart i guess
three.eighteen.
03-31-2003, 09:37 PM
Originally posted by redec
wtf?....you're saying you could do this in asm but you can't figure out how to do it in C?
im not that good at full UNDERSTANDING computer langs...i code in code, none of that pseudocode stuff to get me started, that just confuses me even more
redec
03-31-2003, 10:55 PM
Originally posted by three.eighteen.
im not that good at full UNDERSTANDING computer langs...i code in code, none of that pseudocode stuff to get me started, that just confuses me even more
oh my lord....You'll definatly have to work on that if you're hoping for a profession in this field :P
understanding is key....you must fully understand EVERYTHING before you even start coding. If you don't you're basically shooting in the dark, and hoping it works. You will produce very buggy and spagetti-like code and no one will like you :P
three.eighteen.
04-01-2003, 01:24 AM
oh im not...its freakin cmput 101, just feeling out my interests in 1st year university
speedracer
04-01-2003, 02:40 AM
:confused: So you can't code asm then? :rofl:
Powered by vBulletin® Version 4.2.4 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.