| | |
Double Arrays HELP!!!!!!
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2005
Posts: 3
Reputation:
Solved Threads: 0
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.
==========================================================
<< moderator edit: added [code][/code] tags >>
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.
==========================================================
C++ Syntax (Toggle Plain Text)
# 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; int loader = 0; while (loader < size && (fsData >> dataIn)) if dataIn >= 0 && dataIn <= range) data [loader+=] = dataIn; else cout << 'Data point " << dataIn << "invalid. Ignored. \n"; return loader; 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; }
•
•
•
•
Originally Posted by mr. President
I am having problems with this program and nned help understanding this.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Jun 2005
Posts: 60
Reputation:
Solved Threads: 5
You have multiple errors in your code:
You are calling the function with too few argument's.
You havent declared fsData.
This gotta be a typo, and data aint declared.
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.
C++ Syntax (Toggle Plain Text)
int getData (int numbers [], int size, int range); //....... size= getData (nums, dMAX);
C++ Syntax (Toggle Plain Text)
while (loader < size && (fsData >> dataIn))
C++ Syntax (Toggle Plain Text)
data [loader+=] = dataIn;
C++ Syntax (Toggle Plain Text)
cout << setw (3) << list [i]; if (numPrinted < 4)
i and numPrinted aint declared.
And your function havent braces between them, getData() and printData.
•
•
Join Date: Jul 2005
Posts: 3
Reputation:
Solved Threads: 0
here is what I have amended. am I close?? Please HELP
<< moderator edit: added code tags: [code][/code] >>
I had an error on line 38 below int numPrinted
C++ Syntax (Toggle Plain Text)
/********************************************************************** * 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 [99]; 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 [100]; largest = d[0]; for int i = 0; i < 100; i++) if (largest < d[i]) largest = d[i]; smallest = d[0]; 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:
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:
C++ Syntax (Toggle Plain Text)
for ( int i= 0; int i > 100; i++);
C++ Syntax (Toggle Plain Text)
for ( int i = 0; i < 100; i++ )
I'm here to prove you wrong.
![]() |
Similar Threads
- help with sorting arrays from hightest to lowest (C++)
- C++ BASICS ==> Pointers, Call by Reference/Value, Inheritance, Functions & Arrays (C++)
- Is there an array[x][y][z] in C++ (i.e TRIPLE ARRAY)??? (C++)
Other Threads in the C++ Forum
- Previous Thread: C++ help with Julian day program
- Next Thread: please someone help me urgent
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






