Hey guys:
Can anyone please help me. I am having problems with this program and nned help understanding this. here is the code and the problem. Thanks.

=========Mr. President============

Use a text editor such as Notepad to create a text file that contains several integers. The first integer in the file should be the number of (double) numbers that follow. Name this file assign6.txt.

Write a program that reads from the file the number of numbers to process (the first number in the file) and then reads the remaining numbers into a double array. Assume that there will be no more than 100 numbers to process. After reading all of the numbers into the array, close the file. Then have your program display all of the numbers in the array, five numbers per line, with a precision of 2 and using 10 columns for each number. Don't forget to provide appropriate messages before displaying any numbers. After displaying the numbers in the array, then display the largest and the smallest numbers in the array. Your program should use functions for determining the largest and smallest.

==========================================================

``````# include <iostream>
# include < iomanip>
# include <fstream>
using namespace std;

const int dMAX = 100;

int getData (int numbers [], int size, int range);

void printData (const int numbers[], int size, int lineSize);

int main (void)
{
int size;
int nums [dMAX];

size= getData (nums, dMAX);
printData (nums, size, 10);

return 0;
}

int getData (int data [], int size, int range)
{

char aChar;
int dataIn;
while (loader < size && (fsData >> dataIn))
if dataIn >= 0 && dataIn <= range)
else
cout << 'Data point " << dataIn << "invalid. Ignored. \n";

void printData (const int data [], int size, int lineSize)

cout << setw (3) << list [i];
if (numPrinted < 4)
numPrinted++;
else
{
cout << endl;
numPrinted = 0;
}
cout << endl << endl;
return;
}``````

<< moderator edit: added [code][/code] tags >>

## All 5 Replies

I am having problems with this program and nned help understanding this.

Could you describe your problem (or is it just the syntax errors)? Perhaps you could also post a small sample input file so we don't have to reinvent your wheel?

You have multiple errors in your code:

``````int getData (int numbers [], int size, int range);
//.......
size= getData (nums, dMAX);``````

You are calling the function with too few argument's.

``while (loader < size && (fsData >> dataIn))``

You havent declared fsData.

``data [loader+=] = dataIn;``

This gotta be a typo, and data aint declared.

``````cout << setw (3) << list [i];
if (numPrinted < 4)``````

It seems like you lack a loop here, or else you are only printing out one char.
i and numPrinted aint declared.

And your function havent braces between them, getData() and printData.

``````/**********************************************************************
* Program 6     Files and Arrays
* Programmer
* Date          7/7/2005
* Course        CSCI 221
* Description   Write a program that reads from the file the number of
numbers to process (the first number in the file) and
then reads the remaining numbers into a double array.
Also, the largest and the smallest numbers in the array
will be displayed.
*********************************************************************/

#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

int dMAX ;
int largest;

int getData (int numbers [], int size);
void printData ( const int numbers [], int size, int lineSize);

int main (void)
{
int size;

ifstream myFile;

myFile.open ( "G:\\assign6.txt" );
if ( !myFile )
{
cout << "Error opening input file C:\\DATA.RPT " ;

system ("PAUSE");
}
int numPrinted = 0;
for ( int i= 0; int i > 100; i++);
{
cout << setprecision (2) << setw (10) << list [i];
if (numPinted < 4)
numPrinted++;
else
{
cout << endl;
numPrinted = 0;
}
}

double num ;
largest = d;
for int i = 0; i < 100; i++)
if (largest < d[i])
largest = d[i];

smallest = d;
for (int i = 99; i >= 0; i--)
cout << d [i] << endl;

system ("PAUSE");

return 0;

}
``````

I had an error on line 38 below int numPrinted

I only looked at the line you mentioned, but it sure is a doozy:

``for ( int i= 0; int i > 100; i++);``

Remove int from the condition, you want the loop to iterate 100 times I assume, so it should be i < 100, and a semicolon after the loop tag is interpreted as a loop with an empty body. In other words, change it to this:

``for ( int i = 0; i < 100; i++ )``

I Am Done!! Thanx For All Your Help!!!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.