remove the statement break; that causes your loop to exit after its first pass.
what is the purpose of the max variable? It gets reset to zero every loop iteration, so it really serves no purpose.
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
show us your randomnun( ) function - I'm betting I'll spot the problem in 3.2 nanoseconds.
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
>I'm betting I'll spot the problem in 3.2 nanoseconds.
If it's what I think it is, what makes you think spotting the problem will take that long? ;)
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>I'm betting I'll spot the problem in 3.2 nanoseconds.
If it's what I think it is, what makes you think spotting the problem will take that long? ;)
photons from from screen to eyeball, then a little time for neurons to process.
Is this a new kinder, gentler avatar for you?
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
srand((int)time(0));
Put this function call in main( ), only call it once. Your loop goes so fast, the random number generator is getting reseeded with the same time value again and again, so you will generate the same "random" value repeatedly.
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
>photons from from screen to eyeball, then a little time for neurons to process.
But you already knew what the problem was...we both did. That's negative time there. ;)
>Is this a new kinder, gentler avatar for you?
I can't be myself unless I have a mean looking avatar?
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>But you already knew what the problem was...we both did. That's negative time there.
We both had high probability suspicions, but there's always room for some new twist.
>I can't be myself unless I have a mean looking avatar?
That all depends on the inner you.
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
See comments in the code below pertaining to your random number function
int randomnum()
{
#include<cstdlib> //these two line belong at the beginning of program,
#include<ctime> //not inside a function
//First seed the random number generator
srand((int)time(0)); //this line belongs in main, near its beginning
//it should only be called one time during program run
int random_number;
int span = 10000;
int start = 10000;
//any time you want a random number
//between random_start and random_start + random_span
random_number = rand() % start + span; //good
//That random_number may occur more than once in a program.
gotoxy(25,16); cout << "reference number = "; //what's this do??
//this function generates a number, it should not do any display
return random_number;
}
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228
You'll need to be a bit more specific as to what's not working. What result do you expect, what result actually occurs? Can you narrow down which function/part of a function is misbehaving?
You should write programs in such a way that you can test each function - make a small test program if you need to that feeds input, examines output till you're satisfied that part works.
Trying to whip out the whole thing at one go is a sure recipe for headaches.
vmanes
Posting Virtuoso
1,914 posts since Aug 2007
Reputation Points: 1,268
Solved Threads: 228