| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Please Help :)
my code is all uploaded here http://sourcepost.sytes.net/sourcepost/sourceview.aspx?source_id=22753
my max min and mean functions are all returning zero instead of the actual value. I think this is because i am using 2 arrays, so i need some sort of if statament to sort this out i think, see if you luk at the code, if the user inputs values manually they go into a different array than if they are input from a text file. hope someone out there can help me ![]() thanks dan |
|
#2
|
|||
|
|||
|
Its because, scope of "count" is limited to if {} and else {}. In other words, when "count" gets a value from readarray, the value is destroyed when the control comes out of if loop or else loop.
Remedies: 1. Either declare count as constant integer or define it globally. |
|
#3
|
|||
|
|||
|
Quote:
Thanks for your help mate! I have now changed my declaration of integers to the following: PHP Code:
but i get this error: C:\Documents and Settings\Daniel\My Documents\Uni Work\Alan Goude Programming\Programming\Assignment 2\Assignment 2\Assignment 2.cpp(17) : error C2734: 'count' : const object must be initialized if not extern Being new to all this I have no idea what this means. |
|
#4
|
|||
|
|||
|
No, you got me wrong. I am asking you to move the statement:
count = readarray(int) ; beforethe if loop else decalare count as const int. so that count = readarray () retains its value. Another option is to declare count before the definition of main function. Another solution is to declare count as static integer and then it can be used within if-loop. Basic target is to retain the value of count variable. |
|
#5
|
|||
|
|||
|
For const int , you have to define and declare simultaneously, hence the error.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Please Help :) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|