Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 4th, 2007, 5:19 PM   #11
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 498
Rep Power: 4 Ancient Dragon is on a distinguished road
Re: read integers from file into an array

Quote:
Originally Posted by Simplesouljah View Post
didn't get the PM?
Oh, I thought you would have received one. Then read the Read Me threads at the top of this board -- I just finished adding a new one that shows how to use code tags.
Ancient Dragon is offline   Reply With Quote
Old Dec 4th, 2007, 5:26 PM   #12
Simplesouljah
Newbie
 
Join Date: Oct 2007
Posts: 28
Rep Power: 0 Simplesouljah is on a distinguished road
Re: read integers from file into an array

dont see a <b>read me </b> thread
Simplesouljah is offline   Reply With Quote
Old Dec 4th, 2007, 5:28 PM   #13
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 498
Rep Power: 4 Ancient Dragon is on a distinguished road
Re: read integers from file into an array

you must be looking in the wrong place! Here it is:
Ancient Dragon is offline   Reply With Quote
Old Dec 4th, 2007, 5:29 PM   #14
Simplesouljah
Newbie
 
Join Date: Oct 2007
Posts: 28
Rep Power: 0 Simplesouljah is on a distinguished road
Re: read integers from file into an array

so I post like this

c++ Syntax (Toggle Plain Text)
  1. info here
Simplesouljah is offline   Reply With Quote
Old Dec 4th, 2007, 5:31 PM   #15
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 498
Rep Power: 4 Ancient Dragon is on a distinguished road
Re: read integers from file into an array

Quote:
Originally Posted by Simplesouljah View Post
so I post like this

c++ Syntax (Toggle Plain Text)
  1. info here
YES
Ancient Dragon is offline   Reply With Quote
Old Dec 4th, 2007, 5:37 PM   #16
Simplesouljah
Newbie
 
Join Date: Oct 2007
Posts: 28
Rep Power: 0 Simplesouljah is on a distinguished road
Re: read integers from file into an array

c++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. int myArray[100] = 0;
  11. int i, max, min, maxNumber, minNumber;
  12. string myArray;
  13. max = 0;
  14. min = 0;
  15. int i;
  16. int num;
  17.  
  18. int max = 0;
  19. int min = 0;
  20.  
  21. ifstream inFile;
  22. ofstream outFile;
  23.  
  24. inFile.open ("inputNums.txt");
  25. outFile.open ("finalResults.txt");
  26.  
  27. inFile >> myArray;
  28.  
  29. while( inFile >> myArray[i])
  30. {
  31. if( i == 0) // first time throug
  32. {
  33. max = min = myArray[i];
  34. }
  35. if( myArray[i] > max)
  36. max = myArray[i];
  37. if( myArray[i] < min)
  38. min = myArray[i];
  39. ++i;}
  40.  
  41. {
  42. outFile << "The maximum value is " << max << " found at array index position" << endl;
  43. outFile << endl;
  44.  
  45. outFile << "The minimun value is " << min << " found at array index position" << endl;
  46. outFile << endl;
  47.  
  48. outFile << "There are " << endl;
  49. outFile << endl;
  50.  
  51. outFile << "Thank You!" << endl;
  52.  
  53. inFile.close();
  54. outFile.close();
  55. }
  56.  
  57. system ("pause");
  58. return 0;
  59. }

it's give me error and it's not printing to file
Simplesouljah is offline   Reply With Quote
Old Dec 4th, 2007, 5:39 PM   #17
Simplesouljah
Newbie
 
Join Date: Oct 2007
Posts: 28
Rep Power: 0 Simplesouljah is on a distinguished road
Re: read integers from file into an array

giving me an error on line 10 saying invalid initializer
Simplesouljah is offline   Reply With Quote
Old Dec 4th, 2007, 5:41 PM   #18
Ancient Dragon
PFO God In Training
 
Ancient Dragon's Avatar
 
Join Date: Jun 2005
Location: near St Louis, MO. (USA)
Posts: 498
Rep Power: 4 Ancient Dragon is on a distinguished road
Re: read integers from file into an array

It need braces, like this
int myArray[100] = {0};

And delete line 12.
Ancient Dragon is offline   Reply With Quote
Old Dec 4th, 2007, 5:48 PM   #19
Simplesouljah
Newbie
 
Join Date: Oct 2007
Posts: 28
Rep Power: 0 Simplesouljah is on a distinguished road
Re: read integers from file into an array

c++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. int myArray[100] = {0};
  11. int i,maxNumber, minNumber;
  12.  
  13.  
  14. int num;
  15.  
  16. int max = 0;
  17. int min = 0;
  18.  
  19. ifstream inFile;
  20. ofstream outFile;
  21.  
  22. inFile.open ("inputNums.txt");
  23. outFile.open ("finalResults.txt");
  24.  
  25. inFile >> i;
  26.  
  27. while( inFile >> myArray[i])
  28. {
  29. if( i == 0) // first time throug
  30. {
  31. max = min = myArray[i];
  32. }
  33. if( myArray[i] > max)
  34. max = myArray[i];
  35.  
  36. else if( myArray[i] < min)
  37. min = myArray[i];
  38. ++i;}
  39.  
  40. outFile << "The maximum value is " << max << " found at array index position" << endl;
  41. outFile << endl;
  42.  
  43. outFile << "The minimun value is " << min << " found at array index position" << endl;
  44. outFile << endl;
  45.  
  46. outFile << "There are " << endl;
  47. outFile << endl;
  48.  
  49. outFile << "Thank You!" << endl;
  50.  
  51. inFile.close();
  52. outFile.close();
  53. }

what about now?
Simplesouljah is offline   Reply With Quote
Old Dec 4th, 2007, 6:02 PM   #20
Simplesouljah
Newbie
 
Join Date: Oct 2007
Posts: 28
Rep Power: 0 Simplesouljah is on a distinguished road
Re: read integers from file into an array

my outfile should print

The maximun value is ---- found at array ----
The minimum value is ---- found ar array ----
There are --- values---

I'm not understanding what I'm doing wrong....
what do I use to read the input infile?
Simplesouljah is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem processing file into a char array csrocker101 C++ 1 May 8th, 2007 11:50 PM
Read and write to one file nnxion C 3 Apr 11th, 2006 5:10 PM
How to read unknown total of int data from text file to a 2-dim array in C ladyscarlet99 C 2 Sep 9th, 2005 2:28 AM
How to read unknown total of int data from text file to a 2-dim array in C++? ladyscarlet99 C++ 2 Sep 9th, 2005 1:01 AM
Installing IPB 2.03 bh4575 Other Web Development Languages 0 Apr 23rd, 2005 2:36 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:43 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC