Hotwheelz

07-10-2009, 04:27 PM

This program is supposed to read numbers from a .txt file, add, average and display the highest and lowest value. BUT LOOK AT THIS ****.

Here's the code:

// Assignment 5b Number Analysis.cpp : main project file.

#include "stdafx.h"

#include <iostream>

#include <iomanip>

#include <fstream>

using namespace std;

int main()

{

const int SIZE = 12;

int count;

double numbers[SIZE];

double avg;

double total;

double highest;

double lowest;

ifstream inputFile;

inputFile.open("test.txt");

for (count = 0; count < SIZE; count++)

inputFile >> numbers[count];

inputFile.close();

cout << "The numbers are: ";

for (count = 0; count < SIZE; count++)

cout << numbers[count] << " \n";

for (count = 0; count < SIZE; count++) // calculates total

total += numbers[count];

for (count = 0; count < SIZE; count++) // calculates average

total += numbers[count];

avg = total / SIZE;

for (count = 1; count < SIZE; count++) // calculates highest

{

if (numbers[count] > highest)

highest = numbers[count];

}

for (count = 1; count < SIZE; count++)// calculates lowest

{

if (numbers[count] < lowest)

lowest = numbers[count];

}

cout << "The total sum of the numbers is " << total << "\n";

cout << "The average of the numbers is " << avg << "\n";

cout << "The highest number is " << highest << "\n";

cout << "The lowest number is " << lowest << "\n";

return 0;

}

Here's the code:

// Assignment 5b Number Analysis.cpp : main project file.

#include "stdafx.h"

#include <iostream>

#include <iomanip>

#include <fstream>

using namespace std;

int main()

{

const int SIZE = 12;

int count;

double numbers[SIZE];

double avg;

double total;

double highest;

double lowest;

ifstream inputFile;

inputFile.open("test.txt");

for (count = 0; count < SIZE; count++)

inputFile >> numbers[count];

inputFile.close();

cout << "The numbers are: ";

for (count = 0; count < SIZE; count++)

cout << numbers[count] << " \n";

for (count = 0; count < SIZE; count++) // calculates total

total += numbers[count];

for (count = 0; count < SIZE; count++) // calculates average

total += numbers[count];

avg = total / SIZE;

for (count = 1; count < SIZE; count++) // calculates highest

{

if (numbers[count] > highest)

highest = numbers[count];

}

for (count = 1; count < SIZE; count++)// calculates lowest

{

if (numbers[count] < lowest)

lowest = numbers[count];

}

cout << "The total sum of the numbers is " << total << "\n";

cout << "The average of the numbers is " << avg << "\n";

cout << "The highest number is " << highest << "\n";

cout << "The lowest number is " << lowest << "\n";

return 0;

}