I need assistance with some array related issues

  arrays, c++, max, min
#include <iostream>
#include <iomanip>
#include <fstream>
#include <iomanip>
#include <cmath>
using namespace std;

float a[10];
void createFile();
void Quit();
void cleararrays (float a[]);
int CalcMax ( float a [], float Cmax);
int CalcMin ( float a [], float Cmin);
int CalcAve ( float a [], float ave);
void reading (float a[]);
void Display (float a[], float Cmax, float Cmin, float ave);
int menu();
int choice;

//prototypes 

int main()
{       
float Cmax, Cmin, ave;
// array declarations

    bool flag = true;
    do
    {   
        
        choice = menu();
        switch(choice)
        {
            case 1:  createFile();    
                   break;
                   
            case 2:  cleararrays(a);
                     reading(a);
                     CalcMax (a, Cmax);
                     CalcMin (a, Cmin);
                     CalcAve (a, ave);
                     Display (a, Cmax, Cmin, ave);
                   break;
                        
            case 3:  Quit();
                     flag = false;
                   break;

default : cout << "Error. Please give a number 1 - 3." << endl;
        }
    
    } while (flag);

}


    int menu() {
    
        
    
    cout << "Main Menu "<< endl;
    cout << "1. Create a file."<< endl;
    cout << "2. Display ." << endl;
    cout << "3. Quit." << endl;
    
    cout << "Please enter your choice:" << endl; 
    cin >> choice;
    return choice;

}

void createFile()
 {
    
    int x;
    double number;
    fstream File;
    File.open("number.txt");
    for (x=1;x<=10;x++) {
    cout << "Please enter a number: " << endl;
    cin >> number;
    File << number << " " << endl;
}

    cout << "Written to file 'number.txt;'" << endl;
    
    File.close();
    
    return;
}

// first function (creating a file)


void reading(float a []){

    fstream File;
    File.open("number.txt");
    int ArraySize = 10;
    int count = 0;
    while (count < ArraySize){
        File >> a[count];
        count++;
}
File.close();
}

void cleararrays (float a[])
{
    int x;
    for (x=0;x<10;x++) {
        a[x] = 0;
}
}
int CalcMax ( float a [], float Cmax) {
    int x;
    int num;
    for (x=0;x<11;x++) {
        num = a[x];
        if (num > Cmax) {
            Cmax = num;
        }
    }
    return (Cmax);
}
int CalcMin ( float a [], float Cmin){
    int x;
    int num;
    for (x=0;x<11;x++) {
        num = a[x];
        if (num < Cmin) {
            Cmin = num;
        }
    }
    return (Cmin);
}

int CalcAve ( float a [], float ave){
    int x;
    float num = 0;
    for (x=0;x<11;x++) {
        num = a[x] + num;
    }
    
    ave = num/x;
    return (ave);
}




void Display (float a[], float Cmax, float Cmin, float ave) {
    int x;
    cout << right << "Minimum" << setw(18) << "Maximum"
     << setw(18) << "Average" << endl;
      
    cout << setw(5) << Cmax << setw(17) << Cmin << setw(17)
     << ave << endl; 
      
}

void Quit () {
    
    cout << endl << endl;
    cout << "This program made by: XX XX." << endl;
    return;
}

// quit function 

Seemingly no matter what I input the array returns the value of the min value being some insanely high number while the others are just zeros. I have no idea what is wrong or what to do to fix it (I’m very new to coding so sorry if it is obvious) but it’s due for my college course very soon and I need some help.

Source: Windows Questions C++

LEAVE A COMMENT