C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old March 30th, 2005, 09:34 AM
burns863 burns863 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 4 burns863 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 49 m 32 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old March 30th, 2005, 01:48 PM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 276 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 48 m 58 sec
Reputation Power: 4
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.

Reply With Quote
  #3  
Old March 31st, 2005, 02:38 AM
burns863 burns863 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 4 burns863 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 49 m 32 sec
Reputation Power: 0
Quote:
Originally Posted by Cirus
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.


Thanks for your help mate!
I have now changed my declaration of integers to the following:


PHP Code:
 void main()
{    
int manread;
    
int max;
    
int min;
    
int array[1000];
    const 
int count;
    
int i


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.

Reply With Quote
  #4  
Old March 31st, 2005, 06:31 AM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 276 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 48 m 58 sec
Reputation Power: 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.

Reply With Quote
  #5  
Old March 31st, 2005, 06:49 AM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 276 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 48 m 58 sec
Reputation Power: 4
For const int , you have to define and declare simultaneously, hence the error.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Please Help :)


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT