C++ examples for Data Type:Array
Prints and averages six test scores in array.
#include <iostream> using namespace std; #include <iomanip> void pr_scores(float scores[]); // Prototype void main()// w ww . j av a2s . co m { char s_name[] = "University"; float scores[6] = {8.7, 9.4, 7.0, 7.0, 10.0, 6.7}; float average=0.0; int ctr; pr_scores(scores); for (ctr=0; ctr<6; ctr++) { average += scores[ctr]; } // Computes the average. average /= float(6); cout << "At " << s_name << ", your class average is " << setprecision(2) << average; return; } void pr_scores(float scores[]) { // Prints the six scores. int ctr; cout << "Here are your scores:\n"; // Title for (ctr=0; ctr<6; ctr++) cout << setprecision(2) << scores[ctr] << "\n"; return; }