Charles Tritt / Mbed OS 21_FuncSumEx_v5

Files at this revision

API Documentation at this revision

Comitter:
CSTritt
Date:
Fri Oct 15 18:09:56 2021 +0000
Parent:
117:b40379408898
Commit message:
Cleaned up formatting and comments.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Oct 14 15:48:50 2021 +0000
+++ b/main.cpp	Fri Oct 15 18:09:56 2021 +0000
@@ -9,7 +9,7 @@
  sequences. Switched from return to sleep loop.
 
  Ported to mbed by C. S. Tritt
- Last revised: 10/14/21 (v. 1.2)
+ Last revised: 10/15/21 (v. 1.3)
 */
 #include "mbed.h"
 
@@ -27,6 +27,8 @@
 // main function - Console mode C/C++ execution starts here.
 int main(void) {
     float samples[MAX_COUNT] = {0.0};  // Create & initialize sample array.
+    // Note un-indexed arrays pass as pointers so content of samples can and is 
+    // changed in this call.
     int sampleCount = getData(samples, MAX_COUNT); // Get values.
     float theAverage = myAverage(samples, sampleCount); // Find average.
     userOut(theAverage); // Display results.
@@ -55,12 +57,12 @@
     pc.printf("Number of values to average (Maximum %d)? ", max_size);
     pc.scanf("%d", &nValues); // Caution: scanf is fragile.
     pc.printf("%d was read.\n", nValues); // added by cst.
-    if(nValues > max_size) {
+    if (nValues > max_size) {
         pc.printf("Maximum count exceeded. %d items will be read.", max_size);
         nValues = max_size;
     }
     printf("Enter values:\n");
-    for( int i = 0 ; i < nValues ; ++i) {
+    for(int i = 0 ; i < nValues ; ++i) {
         pc.scanf("%f", &data[i]);
         pc.printf("%f was read.\n", data[i]); // added by cst.
     }