#include<iostream>
using namespace std;
// The max score an array is maxScore // display the score in 100% scale void showScore(double score[], int size, double maxScore);
// copy two functions from previous example // reuse the code, this is something good about writing functions // as the user to input an array with the given size void fillUp(double a[], int size);
// display the array void display(double a[], int size);
int main() { double score[5]; int size = 5;
// ask the user to input score fillUp(score, size);
// display the scores cout << "The scores are : \n"; display(score, size); cout << endl;
// display the score again showScore(score, 5, 50);
// display the scores cout << "After the function call showScore, " << "the scores are : \n"; display(score, size); cout << endl; return 0;
}
void showScore(double score[], int size, double maxScore) { int i; cout << "Scores are : \n"; for(i = 0; i < size; i++) { score[i] = score[i]/maxScore*100; // change the array accidentally cout << score[i] <<"% "; } cout << endl; }
void fillUp(double a[], int size) { int i; //index cout << "Enter " << size << " numbers:\n"; for(i = 0; i < size; i++) { cin >> a[i]; }
cout << "The last array index used is " << (size - 1) << endl;
}
void display(double a[], int size) { int i; // index for(i = 0; i < size; i++) { cout << a[i] << " "; }
}
|