![]() |
Simple (stupid cause I don't know it) basic question
I don't want to have to write 50 if statements for a prog...
how do you find the largest of the numbers that have been input? The thing is, I picked up this book, and they tell you to only use the stuff you've learned so far. But I've only learned if, if...else... and while statements (I haven't JUST learned them, but that's as far as I've gotten in the book. It's an accelerated c++ book, but it goes over the basics in the beginning, with harder problems.) Why I have to read the largest number isn't the point, but the point is I don't know the shortcut of getting the largest number. Can anyone help? simple function call? or what? |
???
I didn't understand any of that. How many numbers will be input? Have you went over string/char management, like arrays? |
Use a bubble sort algorithm
Have all the numbers put into an array, in this case a[10] Have a varible to temporarily hold the value, and make the switch :
for (x=0; x < 10; x++) |
thanks benoit. I was thinking of that, but for my class he won't let me use anything other than the stuff WE already learned, like as a class. We haven't covered arrays yet, but screw it, I'll use it anyway
thanks |
I was bored... here is an example of getting the max number... i believe math.h has a max function you could use as an alternative... i'm sure some more complex data algorithms also have this available... but if all you had to use was the if else, etc... this will work.
:
Enter number (-1 to quit): 4 Enter number (-1 to quit): 19 Enter number (-1 to quit): 432 Enter number (-1 to quit): 51 Enter number (-1 to quit): 5326 Enter number (-1 to quit): 13526523 Enter number (-1 to quit): 234234 Enter number (-1 to quit): -1 The maximum value entered: 13526523 |
thanks infinite. That's excellent, I would have never thought of that lol...
anyways, I was supposed to use a while loop, but what I'll probably do is make a garbage call, like: ......... int x = 0; while (x = 0) ...... do the max number thing..... after all the max stuff is set up.... x = -1; so it quits the loop get what I'm saying, just make a stupid call to get the while statement in, which is a waste of memory and time, but he said he wants a while statement and I can't think of one anyway... Thanks though |
I'll post my code in a sec...
|
lol... change my for"ever" loop into a while
while (;;) { GetNums(): } Normally, I don't like doing homework assignments... because the student doesn't learn that way... Hopefully, this thread was helpful and you have learned some new ways to do stuff... |
that is while ( ; ; )
|
no way, I learn something new everyday... while(;;) Now I've heard everything...
I still think my garbage value function thing was a good idea. lol Thanks infinite, your awesome Note: BTW, I'm using your while(;;) |
| All times are GMT -5. The time now is 4:17 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC