| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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]; } } |
|
#2
|
|||
|
|||
|
no one knows anything that could help??
|
|
#3
|
|||
|
|||
|
What kind of errors are you getting?
|
|
#4
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > please help :) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|