![]() |
|
#1
|
|||
|
|||
Problem that doesn't make sense! Please help!Hi, I'm having a problem with this code. As far as I know it should work fine, but it takes issue with some code in one function. When I compiled this outside of the original program it was fine. Any help would be brilliant! I've underlined the bit that causes the problems
CPP / C++ / C Code:
Last edited by dsmith : 08-May-2004 at 20:00.
Reason: Please use [c] & [/c] for syntax highlighting
|
|
#2
|
|||
|
|||
|
none of your return functions have return statements in them. Every return function must have atleast one return statement in it.
|
|
#3
|
||||
|
||||
|
Hi Shufty. I am not sure if this is the cause of your problem, but it can't help
![]() You declare section as a 5 element array. CPP / C++ / C Code:
However, here in your number function, you are placing 6 elements into the array, so you have gone past your bounds: CPP / C++ / C Code:
In addition later, you go back to a 5-element array with your for statements: CPP / C++ / C Code:
In this case, the for statement loops from 0 to 4. This is correct with your original decleration, but is short with your numbers routine. One last thing. I am not sure why you are using const int n=5 for your for-statements, you could simply put: CPP / C++ / C Code:
You should fix the index overrun either by defining the array as a six-element array and change your for statements or change your number routine to only input 5 numbers. If you are still having problems, let us know. Good Luck, d |
|
#4
|
|||
|
|||
Another day, yet another problemHi again. There's no errors being shown when I compile now BUT the console screen flashes up briefly and disappears and does not do what its supposed to at all. All I can see is it showing some numbers and a sorry message. So for some reason it is skipping the first function I've told it to run in main. I think it may be related to a while statement I added to the numbers function. Here's the latest version of the code (thanks again for everyone's help, I greatly appreciate it!!:-
CPP / C++ / C Code:
Last edited by dsmith : 09-May-2004 at 08:23.
Reason: Please use [c] & [/c] for syntax highlighting
|
|
#5
|
|||
|
|||
|
Quote:
Hi, I need 6 numbers in there, so doesn't using [5] work? Seen as its going 0,1,2,3,4,5 which is six places. Sorry if this sounds stupid but I am very new to all this! |
|
#6
|
|||
|
|||
|
ok I've sorted that problem. I declared confirmchoice as 1 which conflcited with the while statement (always one stupid little thing!
) But now it won't go onto the next function from main. Any ideas? |
|
#7
|
|||
|
|||
|
you need to change the while loop to do{}while(); this way it will enter the loop. currently your function is not entering while loop at all. second, keep in mind that when you declare an array, you declare it with a size: int array[5];
5 is its size. so it can store 5 elements. array storage in c/c++ starts with 0, so your array will store from array[0] to array[4], which is 5 elements. declaration is different than access. if you want 6 elements declare it as array[6], altho the last element will be array[5], if you try to access the 7th element or array[6], the compiler or system won't stop you in most cases but will give you whatever resides there, which will be garbage. so you have to make sure to pay attention. |
|
#8
|
|||
|
|||
|
you still haven't added return statements to your function. either add return statements or change your functions to void. also in order to use the rand() function properly you need to seed the random values first using srand(time(NULL)); otherwise it'll always come up with the same values.
|
|
#9
|
||||
|
||||
|
Quote:
Hi Shufty. When you post code could you please enclose it in [c] and [/c] tags? It really helps to see the code better when it has the proper syntax highlighting. Onto your code. You properly changed your for statements, but you should also declare winning & selection as six element arrays not five. Also, what happens when you run your program? You say it doesn't go on to the next function. How do you know that? The next function is generate which has not i/o to screen. |
|
#10
|
|||
|
|||
|
Quote:
generate has output to screen. also inside your verify function, inside the if statement inside the nested for loops, you declare int accum; accum has already been declared globally. declaring it inside the loops is just assigning it garbage values each time and your function won't perform like it's supposed to at all. also change your int functions to type void if you are not planning on returning anything. |
Recent GIDBlog
Toyota - 2008 November Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Yet another CD burner problem: Lite-On LSC-24082K | Erwin | Computer Hardware Forum | 1 | 22-May-2004 12:28 |
| Another FX 5600 problem (but with details that might shed light on this) | BobDaDuck | Computer Hardware Forum | 2 | 16-Apr-2004 08:53 |
| Linux Kernel Upgrade Mini Howto | dsmith | Computer Software Forum - Linux | 3 | 05-Apr-2004 23:10 |
| problem with php5 cgi installation | fab13 | Apache Web Server Forum | 3 | 19-Nov-2003 10:11 |
| CD Buring Failed | skanth2000 | Computer Hardware Forum | 1 | 15-Nov-2003 04:52 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The