only a couple of hours to go...

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

Join Date: Apr 2006
Posts: 30
Reputation: newgurl is an unknown quantity at this point 
Solved Threads: 0
newgurl newgurl is offline Offline
Light Poster

only a couple of hours to go...

 
0
  #1
Jun 1st, 2006
Hope people dont mind (Lerner and iamthwee), but I would like to start a new post for this assignment of mine. since I think the length of the other one is putting people off and the code is now a lot different.

Can someone help me finalise this (has been going on for DAYS). There are only a few errors I believe.

I need to read (via piping) a txt file which has format:

3435344 @ L Brooks,12 Shaftsbury Road,Burwood NSW 2134
3435344 A 2005/02/22/08:22:41
3435344 A 2005/03/20/08:22:41
3435344 B 2005/03/23/18:22:41
3435344 B 2005/04/10/28:22:41
3435344 C 2005/03/11/08:22:41
3435344 C 2005/05/10/14:22:41
3435344 C 2005/05/19/06:22:43
3435344 D 2005/05/01/01:26:41
3873242 @ N McGoldrick,8 Colless Place,South Melbourne VIC 3205
3873242 B 2005/03/29/02:40:59
3873242 B 2005/05/16/02:40:59
3873242 C 2005/04/07/22:40:59
etc....

use, the cost of stations as A is $2.80, B is $ 2.30 etccc.

to print an invoice with totals per ID. (So one pages has total for ID 3435344, then totals for 3873242....)

This is the code I have prepared to date:

  1. #include <iostream>
  2. #include <string.h>
  3. using namespace std;
  4.  
  5. void printGenericHeading(int&, int&);
  6. void printCustomerHeading(int&, int&);
  7. void readId (int& , int& , int& ,int&, int& );
  8. void readNameAddress (int& , int& , string& , string& , string & , string& ,int& , int& );
  9. void readDateTime (int& , int& , string& , string& , string& ,int& , int& );
  10. void calculateTotalStation (string& , int , double& , double& , double& , double& , double& , double& , int& );
  11. void resetControlTotals(double&);
  12. void printTotalInvoice (int& , char& , double& , double& , double& , double& , double& );
  13.  
  14. const int MAX_DETAIL_LINES =100;
  15. const int MAX_LINE = 100;
  16. const int MAX_SIZE = 20;
  17. double TotalInvoice = 0;
  18. int pageCount = 0;
  19. int lineCount = 0;
  20. bool more= true;
  21.  
  22. void printGenericHeading(int& pageCount, int& lineCount)
  23. {
  24. pageCount = pageCount +1;
  25. cout<<"INVOICE FOR TOLL EXPENSES"<<endl;
  26. cout<<"_________________________"<<endl;
  27. cout<<"TAG\tCUSTOMER\tSTATION"
  28. <<"\t\t\t\t\n";
  29. cout<<"ID\tNAME\t\tID\n";
  30.  
  31. lineCount = 4;
  32. }
  33.  
  34. void printCustomerHeading(int& pageCount, int& lineCount)
  35. {
  36. pageCount = pageCount +1;
  37. cout<<"\t\t\t\t\n";
  38. cout<<"t\t\t\t\tDATE\t\tTIME\tAMOUNT\n\n";
  39.  
  40. lineCount = 3;
  41. }
  42.  
  43. void readId (int& i,int& id, int MAX_SIZE, int& count)
  44. {
  45. id [MAX_SIZE];
  46. count = 0;
  47. do {
  48.  
  49. cin>>id[i];
  50. }
  51. while (count<MAX_SIZE);
  52.  
  53. void readNameAddress (int& MAX_LINE, int& MAX_SIZE, string& name, string& address, string & line, string& inputString,int& count, int& position);
  54. {
  55.  
  56. name [MAX_SIZE];
  57. address [MAX_SIZE];
  58. line;
  59. count =0;
  60.  
  61. do {
  62. getline(cin, line);
  63. int position = line.find (',');
  64. name[count] = line.substr (0, position);
  65. address[count] = line.substr (position+1, MAX_LINE);
  66. count++;
  67. }
  68. while (count<MAX_SIZE);
  69.  
  70. for (int i=0; i<count; i++)
  71. cout <<name[i]<<"\t"<<address[i]<<endl;
  72.  
  73. }
  74. void readDateTime (int& MAX_LINE, int& MAX_SIZE, string& date, string& time, string& inputString,int& count, int& position);
  75. {
  76.  
  77. date [MAX_SIZE];
  78. time [MAX_SIZE];
  79. inputString;
  80. count =0;
  81.  
  82. do {
  83. cerr<<"processing..."<<endl;
  84. getline(cin, inputString);
  85. if(cin.fail()) break;
  86.  
  87. int position = inputString.find ('/');
  88. date [count] = inputString.substr(0, 10);
  89. time [count]= inputString.substr(11,16-11);
  90. count++;
  91. }
  92. while (count<MAX_SIZE);
  93.  
  94. for (int i=0; i<count; i++)
  95. cout <<"t\t\t\t\t"<<date[i]<<"\t\t"<<time[i]<<endl;
  96.  
  97. }
  98. void calculateTotalStation (string& station, int count, double& totalA, double& totalB, double& totalC, double& totalD, double& totalInvoice, double& controlTotal, int& lineCount)
  99. {
  100. totalA = 0;
  101. totalB = 0;
  102. totalC = 0;
  103. totalD = 0;
  104.  
  105. int i = 0;
  106. do
  107. {
  108.  
  109. if (station [i] = 'A')
  110. {
  111. totalA= totalA + 2.20;
  112. cout<<totalA;
  113. }
  114.  
  115. else if(station[i] = 'B')
  116. {
  117. totalB= totalB + 2.80;
  118. cout<<totalB;
  119. }
  120. else if(station[i] == 'C')
  121. {
  122. totalC= totalC + 2.30;
  123. cout<<totalC;
  124. }
  125. else if(station[i] == 'D')
  126. {
  127. totalD= totalD + 3.80;
  128. cout<<totalD;
  129. }
  130.  
  131. totalInvoice = totalA + totalB + totalC + totalD;
  132. cout<<"TOTAL:\t\t\t\t\t\t\$"<<setprecision(2)<<totalInvoice<<endl;
  133. cout<<"\t\t\t\t\t\t_______"<<endl;
  134. cout<<"\t\t\t\t\t\t_______"<<endl;
  135. cout<<"We thankyou for your prompt payment."<<endl;
  136. lineCount = lineCount + 4;
  137. resetControlTotals(controlTotal);
  138.  
  139.  
  140. }while(i < count);
  141. resetControlTotals(controlTotal);
  142. }
  143.  
  144. void resetControlTotals(double& controlTotal)
  145.  
  146. {
  147. controlTotal = 0;
  148. }
  149.  
  150.  
  151.  
  152. int main ()
  153. {
  154. int id;
  155. int prevId;
  156. string name;
  157. string prevName;
  158. double invoiceTotal;
  159. double controlTotal;
  160. int pageCount;
  161. int lineCount;
  162. int i;
  163.  
  164. readId (i, id, MAX_SIZE, count);
  165. prevId =id;
  166. prevName=name;
  167. while(more)
  168. {
  169. if (id!=prevId)
  170. {
  171. calculateTotalStation (station, count, totalA, totalB, totalC, totalD);
  172. prevId= id;
  173. prevName = name;
  174. }
  175. if (lineCount >MAX_DETAIL_LINES)
  176. printGenericHeading(pageCount, lineCount);
  177. printCustomerHeading(pageCount, lineCount);
  178. calculateTotalStation (MAX_SIZE, station, count, totalA, totalB, totalC, totalD);
  179. readId (id, MAX_SIZE, count);
  180. readDateTime (MAX_LINE, MAX_SIZE, date, time, inputString, count, position);
  181. readNameAddress (MAX_LINE, MAX_SIZE, name, address, line, string& inputString,int& count, int& position)
  182. }
  183. printTotalInvoice (MAX_SIZE, station, totalA, totalB, totalC, totalD, totalInvoice);
  184.  
  185. system("pause");
  186. return 0;
  187. }

Can someone help me finalise this? (DUEin the next couple of hours.)
Thanks!
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Re: only a couple of hours to go...

 
0
  #2
Jun 1st, 2006
And the errors are?
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 30
Reputation: newgurl is an unknown quantity at this point 
Solved Threads: 0
newgurl newgurl is offline Offline
Light Poster

Re: only a couple of hours to go...

 
0
  #3
Jun 1st, 2006
In this section:
  1. void readId (int& i,int& id, int MAX_SIZE, int& count)
  2. {
  3. id [MAX_SIZE]; ****
  4. count = 0;
  5. do {
  6.  
  7. cin>>id[i];
  8. }
  9. while (count<MAX_SIZE);

It gives error 45 invalid types `int[int]' for array subscript at ******

In this code :
  1. void readNameAddress (int& MAX_LINE, int& MAX_SIZE, string& name, string& address, string & line, string& inputString,int& count, int& position);
  2. {
  3.  
  4. name [MAX_SIZE]; **************
  5. address [MAX_SIZE];
  6. line;
  7. count =0;
  8.  
  9. do {
  10. getline(cin, line);
  11. int position = line.find (',');
  12. name[count] = line.substr (0, position);
  13. address[count] = line.substr (position+1, MAX_LINE);
  14. count++;
  15. }
  16. while (count<MAX_SIZE);
  17.  
  18. for (int i=0; i<count; i++)
  19. cout <<name[i]<<"\t"<<address[i]<<endl;
  20.  
  21. }
it gives error 56 `name' undeclared (first use this function) at *********

I'll leave it at that for starters...
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

Re: only a couple of hours to go...

 
0
  #4
Jun 1st, 2006
You need to type them. eg

to delcare a string of names you have to specify the array is a string that holds X amount ...

string Names[100]

also another thing why are you pasing MAXSIZE to the function as a parameter?? Its a global meaning you only have to declare it once and you can use it anywhere in your program.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,672
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 261
Lerner Lerner is offline Offline
Posting Virtuoso

Re: only a couple of hours to go...

 
0
  #5
Jun 1st, 2006
Following is a detailed critique of your program as posted and an incomplete program demonstrating how I
would use parallel arrays to complete the project.

  1. #include <iostream>
  2. #include <string.h>
  3. using namespace std;
  4.  
  5. void printGenericHeading(int&, int&);
  6. void printCustomerHeading(int&, int&);
  7. void readId (int& , int& , int& ,int&, int& );
  8. void readNameAddress (int& , int& , string& , string& , string & , string& ,int& , int& );
  9. void readDateTime (int& , int& , string& , string& , string& ,int& , int& );
  10. void calculateTotalStation (string& , int , double& , double& , double& , double& , double& , double& , int& );
  11. void resetControlTotals(double&);
  12. void printTotalInvoice (int& , char& , double& , double& , double& , double& , double& );
  13.  
  14. const int MAX_DETAIL_LINES =100;
  15. const int MAX_LINE = 100;
  16. const int MAX_SIZE = 20;
  17. double TotalInvoice = 0;
  18. int pageCount = 0;
  19. int lineCount = 0;
  20. bool more= true;
  21.  
  22.  
  23. //pageCount and lineCount are glogal variables and shouldn't be passed as parameters
  24. void printGenericHeading(int& pageCount, int& lineCount)
  25. {
  26. pageCount = pageCount +1;
  27. cout<<"INVOICE FOR TOLL EXPENSES"<<endl;
  28. cout<<"_________________________"<<endl;
  29. cout<<"TAG\tCUSTOMER\tSTATION"
  30. <<"\t\t\t\t\n";
  31. cout<<"ID\tNAME\t\tID\n";
  32.  
  33. lineCount = 4;
  34. }
  35.  
  36. //pageCount and lineCount are global variables and shouldn't be passed as parameters
  37. void printCustomerHeading(int& pageCount, int& lineCount)
  38. {
  39. pageCount = pageCount +1;
  40. cout<<"\t\t\t\t\n";
  41. cout<<"t\t\t\t\tDATE\t\tTIME\tAMOUNT\n\n";
  42.  
  43. lineCount = 3;
  44. }
  45.  
  46. //MAX_SIZE is a global variable and shouldn't be passed as a parameter
  47. void readId (int& i,int& id, int MAX_SIZE, int& count)
  48. {
  49. id [MAX_SIZE]; //this is an illegal statement, as MAX_SIZE is not a valid index, MAX_SIZE minus 1 is
  50. //the largest valid index. MAX_SIZE would be the appropriate value if you were
  51. //declaring an array of ID like this: int id[MAX_SIZE];
  52. count = 0;
  53. do {
  54.  
  55. cin>>id[i]; //cin is for input from keyboard, not for reading from file
  56. }
  57. while (count<MAX_SIZE); //count will always be zero, therefore this is an infinite loop
  58.  
  59. //you should really only be reading one ID at a time. It is the first field of each line in the file.
  60. //this will try to force each field in the line into an id until MAX_SIZE ids have been read in
  61. //there is a missing } here to indicate end of function
  62.  
  63.  
  64. //MAX_LINE, MAX_SIZE are global variables and shouldn't be used as parameters
  65. void readNameAddress (int& MAX_LINE, int& MAX_SIZE, string& name, string& address, string & line, string& inputString,int& count, int& position);
  66. {
  67.  
  68. name [MAX_SIZE]; //name is a reference to a single string passed as a parameter, therefore you can't use the [] operator
  69. address [MAX_SIZE]; //address is a reference to a single string passed as a parameter, therefore you can't use the [] operator
  70. line; //this is a meaningless statement
  71. count =0;
  72.  
  73. //this loop looks like you are trying to read all the names and addresses in at once and storing them in arrays
  74. //this would work if all the names/address information were sequential in the file, but they are not
  75. //you need to read them one at a time as they are found, as indicated by the @ char in the file in the station field
  76. do {
  77. getline(cin, line); //you need a filestream here, not cin, to read from the file
  78. int position = line.find (',');
  79. name[count] = line.substr (0, position);
  80. address[count] = line.substr (position+1, MAX_LINE); //you don't need MAX_LINE here at all. Just use the first parameter.
  81. count++;
  82. }
  83. while (count<MAX_SIZE);
  84.  
  85. for (int i=0; i<count; i++)
  86. cout <<name[i]<<"\t"<<address[i]<<endl; //please indent this line to show it is the body of the for loop in a single line
  87.  
  88. }
  89.  
  90.  
  91. //MAX_LINE and MAX_SIZE are global variables and shouldn't be sent as parameters
  92.  
  93. void readDateTime (int& MAX_LINE, int& MAX_SIZE, string& date, string& time, string& inputString,int& count, int& position);
  94. {
  95.  
  96. date [MAX_SIZE]; //date is a reference to a string, not an array, passed as a parameter, therefore the [] is invalid
  97. inputString; //this is a meaningless statement
  98. count =0;
  99.  
  100. //again this loop is an attempt to read in date and time data as if it were sequential in the file, but it isn't
  101. //therefore this will fail.
  102. do {
  103. cerr<<"processing..."<<endl;
  104. getline(cin, inputString); //should be using a file stream, not cin, to read from file
  105. if(cin.fail()) break;
  106.  
  107. int position = inputString.find ('/');//you don't use position in the next two lines, so this line is unecessary
  108. date [count] = inputString.substr(0, 10);
  109. time [count]= inputString.substr(11,16-11);
  110. count++;
  111. }
  112. while (count<MAX_SIZE);
  113.  
  114. for (int i=0; i<count; i++)
  115. cout <<"t\t\t\t\t"<<date[i]<<"\t\t"<<time[i]<<endl; //again indent this line to help yourself, or others
  116.  
  117. }
  118.  
  119.  
  120. void calculateTotalStation (string& station, int count, double& totalA, double& totalB, double& totalC, double& totalD, double& totalInvoice, double& controlTotal, int& lineCount)
  121. {
  122. totalA = 0;
  123. totalB = 0;
  124. totalC = 0;
  125. totalD = 0;
  126.  
  127. //this function will calculate the total the totals of each station and the total of all stations added together
  128. //if all stations visited by a given person are stored in an array called station. For this to work the array
  129. //must be only data for a single person and must be filled element by element as the file is being read
  130. //but I can't find use of station or declaration of station outside of this function, which is a problem.
  131. //The other functions try, but fail, to get all ids, all name/addresses, and all date/times in an array
  132. //so what you could do is get all station A in an array, and all station B in a separate array, and all station C in a
  133. //a separate array, etc. Then when it comes time to calculate totals you can do it index by index where each index
  134. //represents a different person.
  135.  
  136. //If you want to do calculations one person at a time as they are being read from file, then the following code, with
  137. //corrections could work, but it won't work in conjunction with the other functions.
  138. int i = 0;
  139. do
  140. {
  141.  
  142. if (station [i] = 'A') //station is a reference to a string variable, not an array of strings, therefore the [] is invalid
  143. { //'A'is char, "A" is a string, station[i] would be a string if station were an array
  144. //= is the assignment operator, you want the equal operator
  145.  
  146. totalA= totalA + 2.20;
  147. cout<<totalA;
  148. }
  149.  
  150. else if(station[i] = 'B') //same problems as for station[i] = 'A'
  151. {
  152. totalB= totalB + 2.80;
  153. cout<<totalB;
  154. }
  155. else if(station[i] == 'C') //same problems as for station[i] = 'A'
  156. {
  157. totalC= totalC + 2.30;
  158. cout<<totalC;
  159. }
  160. else if(station[i] == 'D') //same problems as for station[i] = 'A'
  161. {
  162. totalD= totalD + 3.80;
  163. cout<<totalD;
  164. }
  165.  
  166. //the following lines should be outside of the do/while loop to be done just once per call to calculateTotalStation
  167. totalInvoice = totalA + totalB + totalC + totalD;
  168. cout<<"TOTAL:\t\t\t\t\t\t\$"<<setprecision(2)<<totalInvoice<<endl;
  169. cout<<"\t\t\t\t\t\t_______"<<endl;
  170. cout<<"\t\t\t\t\t\t_______"<<endl;
  171. cout<<"We thankyou for your prompt payment."<<endl;
  172. lineCount = lineCount + 4;
  173. resetControlTotals(controlTotal);
  174.  
  175.  
  176. }while(i < count);
  177.  
  178.  
  179. resetControlTotals(controlTotal);
  180. }
  181.  
  182. void resetControlTotals(double& controlTotal)
  183.  
  184. {
  185. controlTotal = 0;
  186. }
  187.  
  188.  
  189.  
  190. int main ()
  191. {
  192. int id;
  193. int prevId;
  194. string name;
  195. string prevName;
  196. double invoiceTotal;
  197. double controlTotal;
  198. int pageCount; //this is a duplicate declaration of pageCount
  199. int lineCount; //this is a duplicate declaration of lineCount
  200. int i;
  201.  
  202. readId (i, id, MAX_SIZE, count);
  203. prevId =id;
  204. prevName=name;
  205. while(more)
  206. {
  207. if (id!=prevId)
  208. {
  209. calculateTotalStation (station, count, totalA, totalB, totalC, totalD);
  210. prevId= id;
  211. prevName = name;
  212. }
  213. if (lineCount >MAX_DETAIL_LINES) //how many of the following lines do you want in body of this if???
  214. printGenericHeading(pageCount, lineCount);
  215. printCustomerHeading(pageCount, lineCount);
  216. calculateTotalStation (MAX_SIZE, station, count, totalA, totalB, totalC, totalD);
  217. readId (id, MAX_SIZE, count);
  218. readDateTime (MAX_LINE, MAX_SIZE, date, time, inputString, count, position);
  219. readNameAddress (MAX_LINE, MAX_SIZE, name, address, line, string& inputString,int& count, int& position)
  220. } //this will close out the while loop, it should be indented under the opening brace for the while loop
  221. //more is never changed anywhere in the functions so it will always be true. Therefore this is an
  222. //infinite loop
  223. printTotalInvoice (MAX_SIZE, station, totalA, totalB, totalC, totalD, totalInvoice);
  224.  
  225. system("pause");
  226. return 0;
  227. }



By posting the following I am breaking two rules.

First I am giving you an almost complete solution
to the project. True, it won't work by just a straight copy and paste, but it's pretty darn close to
that.

Second, the following doesn't follow a basic tenet that I follow when writing code for myself. That
tenet is to write no more than a single function before I compile looking for errors. I have not
compiled the following at all. I have no idea how many unintentional errors there are, though I know
I have left some intentional errors such as not completing statements in a couple places, etc.
I think a major part of the code you posted stems from not following same process. You should write
a single function or segment of code and check to see if it does what you want. You should also
write for the specific first and then write to generalize second, unless you are clear how you are
going to generalize. So I would ideally have written code to read just the first line of the file and
make sure I could get an id, station and name/date string. Then I would write code to break the
name/date string apart. Then I would figure out how to read the second line from the file and figure
out how to break it apart. Then I would figure out how to read the entire file line by line. Then
I would figure out how to switch from one person to the next. With each step I would add variables
to the top of the program as necessary to complete each step.

Writing a whole program and then trying to compile debug leads to lots of problems, and lots of problems
that just keep repeating themselves, as in your program code.
  1. #include <iostream>
  2. #include <fstream> //for stream to read from file
  3. using namespace std;
  4.  
  5. const int MAX_SIZE = 100;
  6.  
  7.  
  8. //GOAL: read file data into parallel arrays such that there is a unique index for each person
  9. int main()
  10. {
  11. int count = 0; //to keep track of which index is being used
  12. int prevID = 0; //to help determine when new id found
  13. char station; //may be @, A, B, C, or D
  14. string temp; //holding string
  15.  
  16. //declare parallel arrays to keep track of data from files needed to print invoices
  17. int id[MAX_SIZE]; //to keep track of the id for each index
  18. string name[MAX_SIZE]; //to keep track of the name for each index
  19. string address[MAX_SIZE]; //to keep track of the address of each index
  20. int stationA[MAX_SIZE] = {0}; //to keep track of the number of times station A is found for each id
  21. int stationB{MAX_SIZE] = {0}; //to keep track of the number of times station B is found for each id
  22. int stationC[MAX_SIZE] = {0}; //to keep track of the number of times station C is found for each id
  23. int stationD[MAX_SIZE] = {0]; //to keep track of the number of times station D is found for each id
  24. double totalAmount[MAX_SIZE]; //to keep track of the total amount of a given invoice for a given id
  25.  
  26.  
  27. string dateTime = "06/01/2006/18:00:01"; //date and time of invoice being printed
  28.  
  29. ifstream fin("InputData.txt");
  30. if(!fin)
  31. {
  32. cerr << "unable to open input file" << endl;
  33. exit(1);
  34. }
  35.  
  36. while(fin >> id[count]) //loop will stop when fin goes into fail state
  37. //if a new id is found, assume the rest of the information is present as well
  38. {
  39. fin >> station;
  40. fin.ignore();
  41.  
  42. getline(fin, temp);
  43.  
  44. if(prevId == id) //then increment station visited for this index
  45. {
  46. if(station == 'A')
  47. stationA[count] = stationA[count] + 1;
  48. else if(station == 'B')
  49. stationB[count] = stationB[count] + 1;
  50. else if(station == 'C')
  51. stationC[count] = stationC[count] + 1;
  52. else if(station == 'D')
  53. stationD[count] = stationD[count] + 1;
  54. else
  55. {
  56. cerr << "error in file contents" << endl;
  57. exit(1);
  58. }
  59.  
  60. //date and time are meaningless as far as I'm concerned, if you want to do something with it
  61. //the string is in temp
  62. }
  63. else
  64. {
  65. //station is meaningless in this line so forget it
  66.  
  67. //have a new persons data now so increment count to move on to next index
  68. ++count;
  69.  
  70. //name/address are now in temp and need to be separated into separate strings here and stored
  71. //in the new index of the appropriate arrays
  72. name[count] =
  73. address[count] =
  74. }
  75. }
  76.  
  77. //now that loop has ended determine why
  78. if(!fin.eof())
  79. {
  80. cerr << "file input error." << endl;
  81. exit(1);
  82. }
  83. //else
  84. //EOF found so all the data has been read into the appropriate parallel arrays so we can proceed
  85. //since fin isn't needed any more it can be left in the failed state
  86.  
  87. //Now calculate total cost for each index
  88. for(int i = 0; i <= count; ++i)
  89. totalAmount[i] = stationA[i] * 2.20 + stationB[i] * 2.30 + stationC[i] * 2.80 + stationD[i] * whatever;
  90.  
  91. //Now prepare create a report of all invoices all in the same code
  92. //Prepare an invoice for each person in the database.
  93. //There will be count + 1 number of invoices to print
  94.  
  95.  
  96. //A header for the overall report could go here if desired
  97. for(int i = 0; i <= count; ++i) //index zero through count should be used
  98. {
  99. //if you want to have a personalized header for each person it could go here
  100. cout << name[i] << ' ' << address[i] << endl;
  101. cout << "Date of invoice: 6/1/06";
  102. cout << "Total Due: " << totalAmount[i] << endl << endl;
  103. }
  104. }
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,039
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: only a couple of hours to go...

 
0
  #6
Jun 1st, 2006
Originally Posted by Lerner
Second, the following doesn't follow a basic tenet that I follow when writing code for myself. That
tenet is to write no more than a single function before I compile looking for errors.
That's not so horrible. On one homework assignment, a sparse matrix implementation, I handed in code with multiplication, addition, subtraction, and assignment implemented, but I forgot to check if it even compiled, not to mention worked.

I got very lucky on that one :-)
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Reply

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



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC