So my program keeps displaying weird numbers and the calculations are wrong! I can't seem to figure out whats wrong when i choose the displaystats function. I have also found out that my CreateFileNames function is not writing names onto the txt file and can't seem to fix that?
int main()
{
double a[10]; string FirstName; double Min,Max,Ave;
int choice;
do
{
system("cls");
choice = menu();
switch(choice)
{
case 1: CreateFileNum();
break;
case 2: CreateFileNames();
break;
case 3: Reading(a);
CalculateMax(a,Max);
CalculateMin(a,Min);
CalculateAve(a,Ave);
DisplayStats(a,Max,Min,Ave);
break;
case 4: DisplayNames();
break;
case 5: Quit();
break;
default: cout << "ERROR! INVALID INPUT!" << endl;
}
system("pause");
}while(choice != 5);
}
//This Function Creates the Numbers that will be used
void CreateFileNum()
{
system("cls");
int num, x;
fstream Me;
Me.open("numbers.txt");
for(x=0;x<10;x++)
Me >> a[x];
Me.close();
}
void CalculateMax(double a[], double &Max)
{
Max = a[0];
int x;
for(x=0;x<10;x++)
if(a[x] > Max)
Max = a[x];
}
void CalculateMin(double a[], double &Min)
{
Min = a[0];
int x;
for(x=0;x<10;x++)
if(a[x] < Min)
Min = a[x];
}
void CalculateAve(double a[], double &Ave)
{
double sum;
sum = 0;
int x;
for(x=0;x<10;x++)
sum += a[x];
Ave=sum/10;
}
void DisplayStats(double a[], double Max, double Min, double Ave)
{
int x;
for(x=0;x<10;x++)
cout << a[x] << " " << endl;
cout << setprecision(2) << showpoint << fixed;
cout << "The Max is: " << Max << endl;
cout << "The Min is: " << Min << endl;
cout << "The Ave is: " << Ave << endl;
}
void DisplayNames()
{
}
void Quit()
{
}
int menu()
{
int choice;
cout << "Your Name Main Menu "<< endl;
cout << " 1. Create a Number File" << endl;
cout << " 2. Create a Name File" << endl;
cout << " 3. Display Stats" << endl;
cout << " 4. Display Names in Uppercase" << endl;
cout << " 5. Quit" << endl;
cout << " Please Choose" << endl;
cin >> choice;
return choice;
}
These are the rules:
Your Name Menu
1. Create Number file //store 10 numbers in this file
2. Create Name File //store 10 names in this file
3. Display the stats // display the entire list, min, max, and the average of the list
4. Display Names in uppercase // You choose the format to print the names out in uppercase
5. Quit
Enter Number:
1. Prompt the user for 10 float numbers for your number.txt file. //do not use arrays here
send these numbers to the file in the format of your choice.
2. #Prompt the user for 10 first names for your name.txt file. //do not use arrays here
send this 10 names to the file in the format of your choice.
3. Create 3 functions to calculate the min and max and average and use reference variables to send the answer back to be displayed.. Set the first element of array to min and max. Process the rest of the array.
Must use a reference variable in the functions for Min and Max and Average variables.
Min = array1[0];
for(x=0;x<10;x++)
if (array[x] < Min)
Min = array[x];
4. Display the names in uppercase
5. The quit function should output: This program was created by ?? and answer questions
Requirements
_____ Your main must be the 1st function. Must use prototypes for all your functions except the main
_____ Use a switch statement or if statements for your menu. Must handle illegal menu choice errors.
_____ Must use some kind of looping method to loop through the menu
_____ Must name your files number.txt and name.txt.
_____ Header files needed: #include <cctype> for toupper and #include<cstring>
_____ Recommend using a for loop on number 1 to enter your data. (Function à Create) (NO ARRAYS)
_____ Your file can only have 10 numbers in it. – you choose the format.
_____ There should be separate functions to read in your numbers and names file and send data to these files
_____ Must use a reference variable in the functions for Min and Max and Average variables.
_____ Code to help you change the names to uppercase.
Example:
cin>> First;
for(int x = 0; x < First.length(); x++)
First[x] = toupper(First[x]);
//Send First to your file
_____ Must open and close your files properly. Check for file open errors where ever you open your file.
_____ Declare your number file with fstream and open it with > me.open(“number.txt”, ios::in) or me.open (“number.txt”, ios::out”);
_____ Declare your name file with fstream and open it with > me.open (“name.txt”, ios::in) or me.open (“name.txt”, ios::out”);