2 Compile errors in my array program

Reply

Join Date: Oct 2005
Posts: 20
Reputation: ToySoldier is an unknown quantity at this point 
Solved Threads: 0
ToySoldier's Avatar
ToySoldier ToySoldier is offline Offline
Newbie Poster

2 Compile errors in my array program

 
0
  #1
Nov 22nd, 2005
Need help in finishing this problem. I was doign ok at first but somehow ran into 2 compile errors. Now I'm tired and going in circles. I need a fresh pair of eyes to look it over. This is my first time doing arrays.

  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6.  
  7.  
  8. int main()
  9.  
  10. string first, last, code, name;
  11. int number;
  12. outfile.open("report.txt");
  13. infile.open("people3.txt");
  14.  
  15. {string state_codes
  16. [10]={"AL","CA","FL","GA","IA","KS","MO","MI","MS","NM",};
  17.  
  18. string state_names
  19. [10]={"ALABAMA","CALIFORNIA","FLORIDA","GEORGIA","IOWA","KANSAS","MISSOURI","MICHIGAN","MISSISSIPPI","NEW
  20. MEXICO"};
  21.  
  22. cout<<" PEOPLE REPORT"<<endl;
  23.  
  24. cout<<" FALL 2006"<<endl;
  25.  
  26. cout<<"FIRST "<<" LAST "<<" SS "<<" STATE "<<"
  27.  
  28. STATE"<<endl;
  29.  
  30. cout<<"NAME "<<" NAME "<<" NUMBER"<<" CODE "<<"
  31.  
  32. NAME"<<endl;
  33.  
  34. outfile<<" PEOPLE REPORT"<<endl;
  35.  
  36. outfile<<" FALL 2006"<<endl;
  37.  
  38. outfile<<"FIRST "<<" LAST "<<" SS "<<" STATE
  39.  
  40. "<<" STATE"<<endl;
  41.  
  42. outfile<<"NAME "<<" NAME "<<" NUMBER"<<" CODE
  43.  
  44. "<<" NAME"<<endl;
  45.  
  46. for(i = 0; i<16; i++)
  47. {cout <<left <<setw(2) <<state_codes[i] << " "
  48. <<setw(15) << state_names[i] << endl;
  49. }
  50. return 0;
  51. }

My output should look something like this... any help with finding my 2 compile errors would be appreciated.

  1.  
  2. PEOPLE REPORT
  3. FALL 2005
  4.  
  5. FIRST LAST SS STATE STATE
  6. NAME NAME NUMBER CODE NAME
  7.  
  8. JOE JONES 123-45-6789 NM NEW MEXICO
  9. BOB SMITH 111-11-1111 AL ALABAMA
  10. JOHN DOE 999-12-1234 AA UNKNOWN
  11. JEB BUSH 111-11-1112 FL FLORIDA
  12. JIMMY CARTER 222-22-2222 GA GEORGIA
  13. JANE DOE 999-22-1111 ZZ UNKNOWN
  14. ROBERT WHEATFIELD 888-88-0000 KS KANSAS
  15. JUNE HAYSEED 222-22-3456 IA IOWA
  16. ARNOLD SWARTZ 678-88-1111 CA CALIFORNIA
  17. HENRY FORD 121-21-2121 MI MICHIGAN
  18. VIDA BLUE 234-00-1111 CA CALIFORNIA
  19. JOHN WAYNE 666-66-0000 CA CALIFORNIA
  20. WILLIAM SWAMPRAT 555-55-0987 MS MISSISSIPPI
  21. MATTHEW BLUNT 777-00-1111 MO MISSOURI
  22. DANIEL BOONE 111-99-0000 MO MISSOURI
  23. ZEB WASHINGTON 999-99-9999 X1 UNKNOWN
Here is my infile:

JOE JONES 123-45-6789 NM
BOB SMITH 111-11-1111 AL
JOHN DOE 999-12-1234 AA
JEB BUSH 111-11-1112 FL
JIMMY CARTER 222-22-2222 GA
JANE DOE 999-22-1111 ZZ
ROBERT WHEATFIELD 888-88-0000 KA
JUNE HAYSEED 222-22-3456 IA
ARNOLD SWARTZ 678-88-1111 CA
HENRY FORD 121-21-2121 MI
VIDA BLUE 234-00-1111 CA
JOHN WAYNE 666-66-0000 CA
WILLIAM SWAMPRAT 555-55-0987 MS
MATTHEW BLUNT 777-00-1111 MO
DANIEL BOONE 111-99-0000 MO
ZEB WASHINGTON 999-99-9999 X1
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: 2 Compile errors in my array program

 
0
  #2
Nov 22nd, 2005
could it be that infile and outfile are not defined? It would help if you posted the compile errors.
  1. outfile.open("report.txt");
  2. infile.open("people3.txt");
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: 2 Compile errors in my array program

 
0
  #3
Nov 22nd, 2005
First off, I would suggest adding some tab characters "\t" instead of explicitly adding all the white spaces in. It makes your code really hard to read like it is.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

Re: 2 Compile errors in my array program

 
0
  #4
Nov 22nd, 2005
Here Is The Corrected Code
  1. #include <iostream>
  2. #include<fstream>
  3. #include <string>
  4. #include <iomanip>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.  
  10. string first, last, code, name;
  11.  
  12. ofstream outfile;
  13.  
  14. ifstream infile;
  15.  
  16. outfile.open("report.txt");
  17. infile.open("people3.txt");
  18.  
  19. string state_codes[10]={"AL","CA","FL","GA","IA","KS","MO","MI","MS","NM",};
  20.  
  21. string state_names[10]={"ALABAMA","CALIFORNIA","FLORIDA","GEORGIA","IOWA","KANSAS","MISSOURI","MICHIGAN","MISSISSIPPI","NEW MEXICO"};
  22.  
  23. cout<<" PEOPLE REPORT"<<endl;
  24.  
  25. cout<<" FALL 2006"<<endl;
  26.  
  27. cout<<"FIRST "<<" LAST "<<" SS "<<" STATE "<<" STATE"<<endl;
  28.  
  29. cout<<"NAME "<<" NAME "<<" NUMBER"<<" CODE "<<" NAME"<<endl;
  30.  
  31. outfile<<" PEOPLE REPORT"<<endl;
  32.  
  33. outfile<<" FALL 2006"<<endl;
  34.  
  35. outfile<<"FIRST "<<" LAST "<<" SS "<<" STATE "<<" STATE"<<endl;
  36.  
  37. outfile<<"NAME "<<" NAME "<<" NUMBER"<<" CODE "<<" NAME"<<endl;
  38.  
  39.  
  40. for(int i = 0; i<16; i++)
  41. {
  42. cout <<left <<setw(2) <<state_codes[i] << " "<<setw(15) << state_names[i] << endl;
  43. }
  44. return 0;
  45. }
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 20
Reputation: ToySoldier is an unknown quantity at this point 
Solved Threads: 0
ToySoldier's Avatar
ToySoldier ToySoldier is offline Offline
Newbie Poster

Re: 2 Compile errors in my array program

 
0
  #5
Nov 22nd, 2005
Originally Posted by WolfPack
could it be that infile and outfile are not defined? It would help if you posted the compile errors.
  1. outfile.open("report.txt");
  2. infile.open("people3.txt");
I think that was part of my problem. Thanks... let me get back to it and figure the rest out. I wish I had taken better notes on arrays :o
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 20
Reputation: ToySoldier is an unknown quantity at this point 
Solved Threads: 0
ToySoldier's Avatar
ToySoldier ToySoldier is offline Offline
Newbie Poster

Re: 2 Compile errors in my array program

 
0
  #6
Nov 22nd, 2005
Originally Posted by server_crash
First off, I would suggest adding some tab characters "\t" instead of explicitly adding all the white spaces in. It makes your code really hard to read like it is.
At first I didnt know what you ment but I looked up \t's in my book. AWESOME... I did ask my teacher for an easier way besides spaces but he said for me to just use spaces. I'll surprise him with this program with tabs.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 20
Reputation: ToySoldier is an unknown quantity at this point 
Solved Threads: 0
ToySoldier's Avatar
ToySoldier ToySoldier is offline Offline
Newbie Poster

Re: 2 Compile errors in my array program

 
0
  #7
Nov 22nd, 2005
Originally Posted by sunnypalsingh
Here Is The Corrected Code
Thanks.. I was getting a real headache. Let me get back to it... clean it up with tabs and figure out the rest of it.

After this program, I'm gonna go back to easier examples and start again from the beginning over Thanksgiving break.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,335
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: 236
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: 2 Compile errors in my array program

 
0
  #8
Nov 22nd, 2005
Spaces over tabs -- always.
"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: Nov 2005
Posts: 78
Reputation: perniciosus is an unknown quantity at this point 
Solved Threads: 4
perniciosus's Avatar
perniciosus perniciosus is offline Offline
Junior Poster in Training

Re: 2 Compile errors in my array program

 
0
  #9
Nov 24th, 2005
Ahh the good old printf("Name: %5s", value)...
I am sure I saw a format function somewhere in the stream classes but i have missplaced it!!!
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