Image

Imagegetitaway wrote in Imagecpp

FIXED WITH CORRECT POSTING FORMAT, sorry.



OK, so I haven't touched C++ in about 2+ years and I have a class currently where we need to input the values from the function fish_catch into an array, and display them (this is already done and runs). I then need to run the functions I have defined below to calculate the fishers' specific pay among other things. I am getting an error trying to call the maxValue function saying (I figured I'd try one function at a time as opposed to all at once and throwing a ton of errors):



----------This is fixed
In function 'int main()':

project1.cc:57: error: expected primary-expression before "const"

project1.cc:57: error: expected primary-expression before "const"




I now have this problem:

in function 'intmain()':

project1.cc: error: 'minVal' was not declared in this scope

project1.cc: error: 'maxVal' was not declared in this scope




I'm completely lost as to why I am getting the error as I've consulted multiple books and online resources and it all looks alright to me...




1) /*------------------------ 2) CS 176 3) Project 1: Sept. 27, 2006 4) 5) Name: d 6) ID d 7) Email: d 8) ------------------------*/ 9) 10) #include <iostream> //allows input/output 11) #include <iomanip> //allows manipulation of output 12) #include <string> //string class 13) 14) 15) using namespace std; 16) 17) //prototypes 18) int fish_catch(string, int[]); //function defined elsewhere 19) void maxValue(const int&MAX_WEEKS,const int yield[]); 20) void minValue(const int&MAX_WEEKS, const int yield[]); 21) void totalWeight(const int&maxVal, const int&minVal, const int yield[], int&MAX_WEEKS); 22) void calc3weeksPay(const int&weeksAvail, const int&weeksTotalWeight, const float&payRate); 23) void calcLT3weeksPay(const int yield[], const float&payRate, float&weeklyPay); 24) 25) int main() 26) { 27) //Constant 28) const int MAX_WEEKS=26; // Max # of weeks that will be generated 29) const float payRate=0.9; // pay rate for fishers 30) //Local Declarations 31) int weeksOff = 0; //counter for weeks off 32) int weeksWorked = 0; //counter for weeks worked 33) int weeksAvail = 0; //weeks available for pa 34) int weeksTotal = 0; //total of weeks available after min&max are subtracted 35) int weeksAvg = 0; //average value of available weeks 36) int weeks=0; // number of valid entries in array "yield" 37) int yield[MAX_WEEKS]; //array of pound of fish caught by week 38) float weeklyPay=0.0; //value for weekly pay total 39) string name = "Jill"; //array for name 40) //get fisher's name 41) cerr << "Enter fisher's name: "; 42) cin >> name; 43) 44) //check for end of input list 45) while ( !cin.eof() ) 46) { 47) //get fisher's work results by calling "fish_catch" function 48) weeks = fish_catch(name, yield); 49) //print results 50) cout << "\n" << "Name: " << name << "\n" << "Total weeks: " << weeks << endl; // name, number of weeks worked 51) cout << "Yield: "; //display yield 52) 53) 54) //figure out calling of functions 55) //==============here! 56) maxValue(MAX_WEEKS, yield); 57) minValue(MAX_WEEKS, yield); 58) //totalWeight(int maxVal, int minVal, yield, MAX_WEEKS); 59) /*calc3weeksPay(int, int, float); 60) calcLT3weeksPay(int, float, float);*/ 61) 62) for ( int i = 0; i < weeks; i++ ) 63) { 64) cout << yield[i] << ' '; //pounds of fish caught in week i 65) 66) //if yield is equal to -1 then add 1 to weeksOff 67) if ( yield[i] == -1 ) 68) weeksOff = weeksOff + 1; 69) else 70) weeksWorked = weeksWorked + 1; 71) } 72) 73) cout << endl; 74) cout << "Weeks off: " << weeksOff << "\n"; //display weeks off 75) cout << minVal; 76) cout << maxVal; 77) weeksAvail = weeksWorked - 2; // calculates weeks available for pay 78) cin >> name; 79) } 80) return 0; 81) } 82) 83) //finds maxVal 84) void maxValue(const int&MAX_WEEKS, const int yield[]) 85) { 86) int maxVal=0; //max value 87) for (int mx=0; mx < MAX_WEEKS; mx++) 88) { 89) if (yield[mx] > maxVal) 90) { 91) maxVal = yield[mx]; 92) } 93) } 94) } 95) 96) //finds minVal 97) void minValue(const int&MAX_WEEKS, const int yield[]) 98) { 99) int minVal=0; //max value 100) for (int mn=0; mn > MAX_WEEKS; mn++) 101) { 102) if (yield[mn] < minVal) 103) { 104) minVal = yield[mn]; 105) } 106) } 107) } 108) 109) //Calculates total weight for all weeks and then removes the minimum and maximum values 110) void totalWeight(const int&maxVal, const int&minVal, const int yield[], int&MAX_WEEKS) 111) { 112) float weeksTotalWeight = 0.0; 113) int sum = 0; 114) for (int i=0; i < MAX_WEEKS; i++) 115) { 116) if (yield[i] != -1) //if value in yield[i] is unequal to -1 117) sum += yield[i]; 118) else //else if value in yield[i] is equal to -1 add 0 to sum 119) sum +=0; 120) } 121) 122) weeksTotalWeight = sum - (maxVal + minVal); 123) 124) 125) } 126) 127) //calculates pay for weeks where the fisher worked over 3 or more weeks 128) void calc3weeksPay(const int&weeksAvail, const int&weeksTotalWeight, const float&payRate, float&weeklyPay) 129) { 130) float weeksAvgWeight = 0.0; 131) 132) 133) weeksAvgWeight= weeksTotalWeight / weeksAvail; // calculates weeks average weight 134) 135) weeklyPay = payRate * weeksAvgWeight; // calculates weeks pay 136) 137) cout << "This weeks pay: $" << showpoint << weeklyPay << endl; 138) //formats output to have 3 decimal places and show decimal if it wouldn't normally show up 139) 140) } 141) 142) //will calculate pay for where the fisher worked less than three weeks 143) void calcLT3weeksPay(const int yield[], const float&payRate, float&weeklyPay) 144) { 145) weeklyPay = yield[0] * payRate; //weeklyPay is the most recent weeks catch * payRat 146) 147) cout << "This weeks pay: $" << showpoint << weeklyPay << endl; 148) //formats output to have 3 decimal places and show decimal if it wouldn't normally show up 149) } 150)
}