#include <iostream>
#include <fstream>
#include <cctype>
#include <iomanip>
usingnamespace std;
float average(int grades[]);
int main()
{
ifstream sourcefile;
sourcefile.open("a5.txt");
if(!sourcefile)
{
cout << "imput failed" << endl;
return 0;
}
int grades[25];
int bill;
int max = 0;
for(bill = 0 ; bill < 25 ; bill++)
{
sourcefile >> grades[bill];
if (grades[bill] > max)
{
max = grades[bill];
}
cout << grades[bill] << endl;
}
for(bill = 0 ; bill < 25 ; bill++)
{
cout << grades[bill] << endl;
}
int min = 100;
for(bill = 0 ; sourcefile ; bill++)
{
min = grades[bill];
}
cout << "The top grade is " << max << endl;
cout << "The lowest grade is " << min << endl;
// it says the min is 100 for some reason... I don't think I'm using the right
// technique
// In the section below the program completely crashes.
cout << "this is a printout of the array, to make sure it's not being modifed" << endl;
ofstream output;
output.open("output.txt");
for(bill = 0 ; bill < 25 ; bill++)
{
output << grades[bill] << endl;
}
return 0;
}
float average(int grades[])
{
int total = 0;
int bill = 0;
float average;
for (bill ; bill < 25 ; bill++)
{
total = total + grades[bill];
}
cout << "total of all grades = " << total << endl;
average = float(total) / 25;
cout << "Average of all grades = " << average << endl;
return average;
}
I found the maximum, the minimum, and the average just fine, but I think there's something wrong with how I find the minimum.
How would you guys reccomend finding the minimum value of an array? I tried to use a for loop and do the reverse of what I did to find the maximum value.
Oh, I put the wrong thing up, I messed it up trying to find my mistake and I forgot to put up a working model
it works now, but something really strange kept happening
it kept glitching at my for loop end condition
When I had the end condition be the end of the file (sourcefile), it worked fine, but when I set it to when my count variable is less than 25 (bill < 25) I got a WINDOWS error message, not a MVC++ error like usual
Do you think that's vista screwing up on me? The condition "bill < 25" works great now =\