Wednesday 15 June 2011

arrays - functions to find average and peak value in c++ -


My assignment:

The program should show 2 functions, to calculate the average of values ​​in one For the array (returning the result as repeating the result) and finding one to return the extreme value (returned result as unsigned value) in the array. In the array (unsigned ints) and array (unsigned int), the number of values ​​should be passed as parameters in the form of a function.

Can anyone please explain my code to fix ??

  #include & lt; Iostream & gt; using namespace std; # Size two double search extrusion (unsigned int); Unsigned findPeak (unsigned int); Unsigned number [SIZE] = {47, 1, 0, 1324, 99, 1000, 65536, 19, 0, 24, 000}; Unsigned amount; Unsigned peak; Int main () {Double average; For (int i = 0; i & lt; SIZE; i ++) {sum + = numbers [i]; } Average = Search Avg (number [size]); Cout & lt; & Lt; "Average value is:" & lt; & Lt; Avg & lt; & Lt; Endl; Peak = SearchPack (number [size]); Cout & lt; & Lt; "Extreme Value:" & lt; & Lt; Summit & lt; & Lt; Endl; } Double Search Average (unsigned amount) {Double average; Average = sum / SIZE; Return average; } Unsigned findPeak (unsigned int *) {for (int i = 0; i  

Running version:

  # Include & lt; Iostream & gt; using namespace std; Double search profitable (unsigned int *, unsigned int); Unsigned int findPeak (unsigned int *, unsigned int); Int main () {const int size = 10; Unsigned multiplication number [] = {47, 1, 0, 1324, 99, 1000, 65536, 19, 0, 24, 000}; Double average = Search average (number, size); Cout & lt; & Lt; "Average value is:" & lt; & Lt; Avg & lt; & Lt; Endl; Unsigned int peak = findPeak (number, size); Cout & lt; & Lt; "Extreme Value:" & lt; & Lt; Summit & lt; & Lt; Endl; } Double Search Adjective (unsigned int * number, unsigned full size) {unsigned int sum = 0; For (int i = 0; i  peak) {peak = numbers [i]; }} Return summit; }  

Remarks: You should avoid global variables. I think calculation of yoga makes more sense in findAverage () . Then it must pass the array; Missed a * declaration of findPeak , it did not match the definition, to pass any array, you can enter any [...] should not be given. Just type the first element by typing the array name. average = sum / SIZE; First evaluates sum / SIZE by dividing an integer, so the result is cut

to force you to make one device Must have an operand for

No comments:

Post a Comment