Double Arrays HELP!!!!!!

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2005
Posts: 3
Reputation: mr. President is an unknown quantity at this point 
Solved Threads: 0
mr. President mr. President is offline Offline
Newbie Poster

Double Arrays HELP!!!!!!

 
0
  #1
Jul 7th, 2005
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.

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

  1. # include <iostream>
  2. # include < iomanip>
  3. # include <fstream>
  4. using namespace std;
  5.  
  6. const int dMAX = 100;
  7.  
  8. int getData (int numbers [], int size, int range);
  9.  
  10. void printData (const int numbers[], int size, int lineSize);
  11.  
  12. int main (void)
  13. {
  14. int size;
  15. int nums [dMAX];
  16.  
  17. size= getData (nums, dMAX);
  18. printData (nums, size, 10);
  19.  
  20. return 0;
  21. }
  22.  
  23. int getData (int data [], int size, int range)
  24. {
  25.  
  26. char aChar;
  27. int dataIn;
  28. int loader = 0;
  29. while (loader < size && (fsData >> dataIn))
  30. if dataIn >= 0 && dataIn <= range)
  31. data [loader+=] = dataIn;
  32. else
  33. cout << 'Data point " << dataIn << "invalid. Ignored. \n";
  34.  
  35. return loader;
  36.  
  37. void printData (const int data [], int size, int lineSize)
  38.  
  39. cout << setw (3) << list [i];
  40. if (numPrinted < 4)
  41. numPrinted++;
  42. else
  43. {
  44. cout << endl;
  45. numPrinted = 0;
  46. }
  47. cout << endl << endl;
  48. return;
  49. }
  50.  
<< moderator edit: added [code][/code] tags >>
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,382
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 242
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Double Arrays HELP!!!!!!

 
0
  #2
Jul 7th, 2005
Originally Posted by mr. President
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?
"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
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 60
Reputation: zyruz is an unknown quantity at this point 
Solved Threads: 5
zyruz zyruz is offline Offline
Junior Poster in Training

Re: Double Arrays HELP!!!!!!

 
0
  #3
Jul 7th, 2005
You have multiple errors in your code:

  1. int getData (int numbers [], int size, int range);
  2. //.......
  3. size= getData (nums, dMAX);
You are calling the function with too few argument's.

  1. while (loader < size && (fsData >> dataIn))
You havent declared fsData.

  1. data [loader+=] = dataIn;
This gotta be a typo, and data aint declared.

  1. cout << setw (3) << list [i];
  2. 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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 3
Reputation: mr. President is an unknown quantity at this point 
Solved Threads: 0
mr. President mr. President is offline Offline
Newbie Poster

Re: Double Arrays HELP!!!!!!

 
0
  #4
Jul 7th, 2005
here is what I have amended. am I close?? Please HELP

  1. /**********************************************************************
  2. * Program 6 Files and Arrays
  3. * Programmer
  4. * Date 7/7/2005
  5. * Course CSCI 221
  6. * Description Write a program that reads from the file the number of
  7.   numbers to process (the first number in the file) and
  8.   then reads the remaining numbers into a double array.
  9.   Also, the largest and the smallest numbers in the array
  10.   will be displayed.
  11. *********************************************************************/
  12.  
  13. #include <iostream>
  14. #include <iomanip>
  15. #include <fstream>
  16. using namespace std;
  17.  
  18. int dMAX [99];
  19. int largest;
  20.  
  21. int getData (int numbers [], int size);
  22. void printData ( const int numbers [], int size, int lineSize);
  23.  
  24. int main (void)
  25. {
  26. int size;
  27.  
  28. ifstream myFile;
  29.  
  30. myFile.open ( "G:\\assign6.txt" );
  31. if ( !myFile )
  32. {
  33. cout << "Error opening input file C:\\DATA.RPT " ;
  34.  
  35. system ("PAUSE");
  36. }
  37. int numPrinted = 0;
  38. for ( int i= 0; int i > 100; i++);
  39. {
  40. cout << setprecision (2) << setw (10) << list [i];
  41. if (numPinted < 4)
  42. numPrinted++;
  43. else
  44. {
  45. cout << endl;
  46. numPrinted = 0;
  47. }
  48. }
  49.  
  50. double num [100];
  51. largest = d[0];
  52. for int i = 0; i < 100; i++)
  53. if (largest < d[i])
  54. largest = d[i];
  55.  
  56. smallest = d[0];
  57. for (int i = 99; i >= 0; i--)
  58. cout << d [i] << endl;
  59.  
  60. system ("PAUSE");
  61.  
  62. return 0;
  63.  
  64. }
<< moderator edit: added code tags: [code][/code] >>

I had an error on line 38 below int numPrinted
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,745
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 739
Team Colleague
Narue's Avatar
Narue Narue is online now Online
Code Goddess

Re: Double Arrays HELP!!!!!!

 
0
  #5
Jul 7th, 2005
I only looked at the line you mentioned, but it sure is a doozy:
  1. 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:
  1. for ( int i = 0; i < 100; i++ )
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 3
Reputation: mr. President is an unknown quantity at this point 
Solved Threads: 0
mr. President mr. President is offline Offline
Newbie Poster

Re: Double Arrays HELP!!!!!!

 
0
  #6
Jul 8th, 2005
I Am Done!! Thanx For All Your Help!!!!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC