the total, average, highest, lowest, and sort the data. I am having some errors and i don't know how to fix them.
Here is my code
#include <iostream>
#include <iomanip>
using namespace std;
// Prototypes
int readData(int [], int);
void sortArray(int [], int);
void showArray(int [], int);
int getLowest(int [], int);
int getHighest(int [], int);
float findTotal(float [], int, float &, float &);
int main()
{
const int size = 50;
int highest, lowest;
int numbers[size];
float avg, total;
readData(numbers, size);
cout << "There are " << count << "number(s) in the file." << endl;
sortArray(numbers, size);
getHighest(numbers, size);
cout << "The highest number is: " << highest << endl;
getLowest(numbers, size);
cout << "The lowest numeber is: " << lowest << endl;
findTotal(numbers, size)
cout << "The total is: " << total << endl;
cout << "The Average is: " << avg << endl;
}
int readData (int numbers[], int size)
{
const int name_size = 31;
int numbers[size];
int count;
ifstream inputFile; // Input file stream object
char filename[name_size];
cout << "Please enter the file name: " << endl;
cin >> setw(name_size) >> filename;
inputFile.open(filename); // Open the file.
if (!inputFile)
{
cout << "Error opening the file!" << endl;
exit(190)
// Read the numbers from the file into the array.
for (count = 0; count < size; count++)
inputFile >> numbers[count];
// Close the file.
inputFile.close();
return count;
}
// Sort the Array
void sortArray(int numbers[], int size)
{
bool swap;
int temp;
do
{
swap = false;
for (int count = 0; count < (size - 1); count++)
{
if (numbers[count] > numbers[count + 1])
{
temp = numbers[count];
numbers[count] = numbers[count + 1];
numbers[count + 1] = temp;
swap = true;
}
}
} while (swap);
}
// Print the Sorted Array
void showArray(int numbers[], int size)
{
cout << "Your Numbers are: ";
for (int count = 0; count < size; count++)
cout << numbers[count] << " ";
cout << endl;
}
// Highest Function
int getHighest(int numbers[], int size)
{
int count;
int highest;
highest = numbers[0];
for (count = 1; count < size; count++)
{
if (numbers[count] > highest)
highest = numbers[count];
}
return highest;
}
// Lowest Function
int getLowest(int numbers[], int size)
{
int count;
int lowest;
lowest = numbers[0];
for (count = 1; count < size; count++)
{
if (numbers[count] < lowest)
lowest = numbers[count];
}
return lowest;
}
// Total and Average function
float findTotal(float numbers[], int count, float &total, float &avg)
{
for(int count = 0, count < size, count++)
total += numbers[count];
avg = total / count;
return;
}
First error is here
readData(numbers, size); cout << "There are " << count << "number(s) in the file." << endl;Where the error is no match for opporator
Second error is here
findTotal(numbers, size);
The error is in the call here. Say cant convert int to float.
Third
int readData (int numbers[], int size)
{
The error is when im writing the function it says "a function deffiniton is not allowed here" this happens before all
my functions.
There are some small errors too that i cant find
Please help
Thanks
This post has been edited by Retro Batman: 06 December 2009 - 03:23 PM

New Topic/Question
This topic is locked




MultiQuote





|