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 November 17th, 2004, 03:23 PM
dfenley dfenley is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 5 dfenley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
please help :)

im trying to write a program that counts scores from another file and give avg., highest, and lowest. heres what ive got so far, i keep geting a few error i cant fix.
#include<iostream>

#include<fstream>

#include<cmath>

#include<iomanip>

usingnamespace std;

void Findhighest (constint [ ], int , int&);

void Findlowest (constint [ ], int , int&);

void Findaverage (constint [ ], int , int&);

int main()

{



int highest,lowest,average;

ifstream datafile;
//open the data file

datafile.open("class.txt");



int scores[101];



for (int count = 0; count < 100; count++)

datafile>> scores[count];





Findaverage (scores, count, average);

Findhighest (scores, count, highest);

cout << endl << "Average was: " << average << endl;

cout << "Highest was: " << highest << endl;

datafile.close();

return 0;

}



void FindAverage( /* in */constint scores[ ],

/* in */int count,

/* out */int & avg)

{

int m;

int total = 0;

for (m = 0; m < count; m++)

{

total = total + scores[m];

}

avg =
int (float(total) / float(count) + .5);



}

void Findhighest ( /* in */constint scores[ ],

/* in */int count,

/* out */int& highest)

{

int m;

highest = scores[0];

for (m = 0; m < count; m++)

{

if (scores[m] > highest)

highest = scores[m];

}

}

void Findlowest ( /* in */constint scores[ ],

/* in */int count,

/* out */int& lowest)

{

int m;

lowest = scores[0];

for (m = 0; m < count; m++)

{

if (scores[m] > lowest)

lowest = scores[m];

}

}


Reply With Quote
  #2  
Old November 18th, 2004, 11:33 AM
dfenley dfenley is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 5 dfenley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
no one knows anything that could help??

Reply With Quote
  #3  
Old November 18th, 2004, 02:07 PM
Kernel Mustard Kernel Mustard is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 32 Kernel Mustard User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
What kind of errors are you getting?

Reply With Quote
  #4  
Old November 18th, 2004, 02:48 PM
code_geek code_geek is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 9 code_geek User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
besides what i assume is a typo (in the fourth line, usingnamespace std; should be using namespace std;), you need to pass pointers to your findaverage and findhighest functions for the third parameter. if i am not mistaken, the prototype should look like findAverage(constint[], int, int*) and the call should look like findAverage(scores, count, &average)
* means "pointer to"
& means "address of"
if this doesn't work, trying switching the * and &, i might have them mixed up

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 3 hosted by Hostway