![]() |
|
#1
|
|||
|
|||
Nested for loop with functionI have to write a program that calculates the number of times a specific number occurs when the number is generated useing the sum of a series of random number calulations.
I know that the first loop, loops the number of time you want the calculation to occur. The second loop, loops for the number of random numbers you wish to use in the calculation. I don't know if the sum function will corectly add up the random numbers in the second loop. CPP / C++ / C Code:
The complier gives out the following errors when I tried to complie: Quote:
|
|
#2
|
|||
|
|||
|
Quote:
Quote:
So: go through the compiler messages one-by-one: What's wrong with line 43, something to do with "count"? (No, I'm not going to tell you: look at it.) Fix this line and recompile. You will get something about an undefined symbol 'i' on a certain line (probably line 47). What does that mean? Fix it and recompile. If there are any specific messages that you don't understand, maybe someone here can help. It's really faster for you (and perhaps even edifying) if you make as many corrections as you can, instead of just throwing things up on the web and hoping that someone will fix things for you. Regards, Dave |
|
#3
|
|||
|
|||
|
Just to help you with errors.
Homework_4-3.cpp:43: error: `count' undeclared (first use this function) this should be CPP / C++ / C Code:
Homework_4-3.cpp:43: error: (Each undeclared identifier is reported only once for each function it appears in.) Homework_4-3.cpp:47: error: `i' undeclared (first use this function) you have not declared variable i, before using it. You can either do it at the begining of main() or in for loop itself (since you are using C++) Homework_4-3.cpp:51: error: void value not ignored as it ought to be This error is displayed because your generate function is declared to return nothing (void), where as in definition of function you are returning an integer value. You need to change your function prototype (above main() ) and function definition to change the return type from "void" to "int". Homework_4-3.cpp:53: error: `If' undeclared (first use this function) "If" is wrong, "if" is correct syntax. Homework_4-3.cpp:54: error: syntax error before `>>' token a semicolan ";" is missing on the line "cin >> cnt = cnt + 1" Homework_4-3.cpp: In function `void generate(int, int)': Homework_4-3.cpp:64: error: `x' undeclared (first use this function) Homework_4-3.cpp:64: error: `y' undeclared (first use this function) The reason for both of the above error is that. You are using variables "x" and "y" without actually declaring them. Also, the generate function definition has two variable declarations for "c" and "d" but they are not being used anywhere in the generate() function. Is x and y supposed to be c and d respectively ? Just a guess. If yes, then you can straight away replace x and y with c and d respectively , in function. Homework_4-3.cpp:64: error: return-statement with a value, in function declared with a void return type This error is again because of of return type missmatch for function generate(). Taking care of error "Homework_4-3.cpp:51:" as mentioned above will eliminate this complier error. |
|
#4
|
|||
|
|||
The compiler returned a weird errorI fixed the problems from before, but when I went to compile I got this strange compiler error. I don't understand what it is trying to tell me. (I don't even have a 'operator='.)
Quote:
This is my revised code; CPP / C++ / C Code:
|
|
#5
|
|||
|
|||
|
Quote:
Is this statement valid ? I am not a c++ programmer myself. But what I know about it, it does not look correct to me. Are you trying to do ? CPP / C++ / C Code:
|
|
#6
|
||||
|
||||
|
Quote:
__________________
Age is unimportant -- except in cheese |
|
#7
|
|||
|
|||
It will compile, but won't run all the wayI fixed the cnt error and now it will compile. When I run the program, it will only run up to the point where I enter the number that I am looking for. Why is it stopping and not performing the loops?
|
|
#8
|
|||
|
|||
|
Pls post your new code and the output.
Thanks, |
|
#9
|
|||
|
|||
Here is the updated codeCPP / C++ / C Code:
|
|
#10
|
||||
|
||||
|
Quote:
I bet you can fix it now. :-) __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs Last edited by cable_guy_67 : 08-Nov-2004 at 11:15.
Reason: commented cin in loop
|
Recent GIDBlog
Python ebook by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to interpret characters as they are being entered? | nkhambal | C Programming Language | 18 | 14-Feb-2006 10:41 |
| Revising Script style ?????? | pepee | MySQL / PHP Forum | 4 | 14-Apr-2004 04:59 |
| Another problem dealing with main() and driver function | tommy69 | C Programming Language | 4 | 20-Mar-2004 19:46 |
| Calling functions within a function | spudtheimpaler | C Programming Language | 5 | 02-Mar-2004 08:02 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The