473,320 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

still having problems with entering truck name and truck number

Ok Im still having problems, Im wanting the name that I enter as the truck name to always be the same, so if the user is asked to enter the truck name it must be one thing, and if anything other it shoud make the user retry, I dont want it to just put any name in, also the truck id is allowing the user again to put any number in and it takes it and the program runs, but i want it to remember the truck number, add to the truck inventory and I want it to be the correct number, not able to just put in any number again. Im still wanting the user to enter the days date,not sure where to put that in, should be at the beginning of program, but still not able to make that work as well. Also right now the program has a couple of errors line 40 declaration terminated incorrectly and line 104 expression syntax in function main [ ]. I am using Borland c++. Again any help would be greatly appreciated..Thank you

/
Expand|Select|Wrap|Line Numbers
  1. *This program allows the user to add and remove trucks to their
  2. inventory. It also allows them to add and remove donations
  3. from the truck chosen. It also display a chart of
  4. what trucks are in inventory, with the name of the
  5. truck and the amount of donations in each one.th use will also be able to
  6. enter the current days date and print out the days inventory.
  7. */
  8. #include <iostream.h>
  9. #include <iomanip.h>
  10. #include <stdlib.h>
  11. #include <conio.h>
  12. #include <string.h>
  13. #include <ctype.h>
  14.  
  15. #define max_trucks 200
  16. #define max_capacity 250
  17.  
  18. class GOODWILL_TRUCK
  19. {
  20. private:
  21. int ID_NUM;
  22. int TRUCK_CAP;
  23. int DON_ON_HAND;
  24. char *TRUCK_NAME;
  25. static int NUM_TRUCKS;
  26.  
  27. public:
  28. GOODWILL_TRUCK (int id, char *Truck_Name, int don= 0);
  29. ~ GOODWILL_TRUCK ();
  30. int ADD_DON (int amt);
  31. int REMOVE_DON (int amt);
  32. inline int GET_ID_NUM (){return ID_NUM;}
  33. inline int GET_CAP () {return TRUCK_CAP;}
  34. inline int GET_CONT() {return DON_ON_HAND;}
  35. inline char* GET_NAME () {return TRUCK_NAME;}
  36. static int TOTAL_TRUCKS ();
  37. };
  38. int GOODWILL_TRUCK::NUM_TRUCKS = 0;
  39.  
  40. GOODWILL_TRUCK (int id, char *Truck_Name, int don)
  41. {
  42. ID_NUM = id;
  43. TRUCK_NAME = new char [strlen(T_Name)+1];
  44. strcpy (TRUCK_NAME, T_Name);
  45. DON_ON_HAND = don;
  46. TRUCK_CAP = 250;
  47. ++NUM_TRUCKS;
  48. }
  49. int GOODWILL_TRUCK::ADD_DON (int amt)
  50. {
  51.     if (DON_ON_HAND + amt > TRUCK_CAP)
  52. return -1;
  53. else
  54.     return DON_ON_HAND += amt;
  55. }
  56. int GOODWILL_TRUCK::REMOVE_DON (int amt)
  57. {
  58.     if (DON_ON_HAND - amt < 0)
  59. return -1;
  60.     else
  61.         return DON_ON_HAND -= amt;
  62. }
  63.  
  64. GOODWILL_TRUCK::~GOODWILL_TRUCK ()
  65. {
  66. delete [] TRUCK_NAME;
  67. }
  68. int OIL_TANK::TOTAL_TRUCKS()
  69. {
  70. return NUM_TRUCKS;
  71. }
  72. GOODWILL_TRUCK* create_truck();
  73. void display (GOODWILL_TRUCK&);
  74.  
  75. void main ()
  76. {
  77.     int don_amt,
  78.     result,
  79.     count = 0,
  80.     choice;
  81.     char select  = ' ';
  82.     char answer = ' ';
  83.  
  84. GOODWILL_TRUCK* truck_table[max_trucks];
  85. do
  86. {
  87. cout << "\n                WELCOME TO THE MERS/GOODWILL TRUCK INVENTORY";
  88. cout << "\n\nPlease choose a number from the menu below.";
  89. cout << "\nl. Add a truck to inventory.";
  90. cout << "\n2. Add donations to a truck.";
  91. cout << "\n3. Remove donations from a truck.";
  92. cout << "\n4. Display the trucks in inventory.";
  93. cout << "\n5. Quit the Program.";
  94. cout << "\n\nPlease enter your selection now: ";
  95. cin >> select;
  96. clrscr ();
  97. switch (select)
  98. {
  99. case '1':
  100. cout << "\nDo you want to add a truck to inventory? (Y/N): ";
  101. cin >> answer;
  102. while (toupper(answer) == 'Y' && count < max_trucks)
  103. {
  104. *truck_table& [count] = create_truck();
  105. ++count;
  106. cout << "\nDo you want to add a truck to inventory? (Y/N): ";
  107. cin >> answer;
  108. }
  109. break ;
  110. case '2':
  111. cout << "\nTo which truck would you like to add donations?(1-15): ";
  112. cin >> choice;
  113. if (choice < 1 || choice > count)
  114. {
  115. cout << "\n\nINVALID ENTRY!!! ";
  116. break;
  117. }
  118. else
  119. {
  120. cout << "n\nPlease enter the amount of donations to add: ";
  121. cin >> don_amt;
  122. result = truck_table[choice - 1]->ADD_DON (don_amt);
  123. if (result < 0)
  124. cout<< "\nERROR Truck capacity is not large enough!!!\n";
  125. else
  126. cout << "\nDonations Added!!! ";
  127. break;
  128. }
  129. case '3':
  130. cout << "\nFrom which truck would you like to remove donations? (1-max): ";
  131. cin >> choice;
  132. if (choice < 1 || choice > count)
  133. {
  134. cout << "\n\nINVALID ENTRY!!! ";
  135. break;
  136. }
  137. else
  138. cout << "\nPlease enter the amount of donations to remove: ";
  139. cin >> don_amt;
  140. result = truck_table[choice - 1]->REMOVE_DON (don_amt);
  141. if (result < 0)
  142. cout <<"\nERROR Truck does not have enough donations in it! !!\n";
  143. else
  144. cout << "\nDonations Removed!!! ";
  145.  
  146. break;
  147.  
  148. case '4':
  149. for (int x = 0; x < count; ++x)
  150. display(*truck_table[x]);
  151. break;
  152.     }
  153. }
  154. while (select != '5');
  155. cout << "\n\n\n\n                       THANK YOU";
  156. cout << "\n\n                       GOODBYE";
  157. for (int x = 0; x < count; ++x)
  158. delete truck_table[x];
  159. }
  160. GOODWILL_TRUCK* create_truck()
  161. {
  162. int id_num,
  163. donations = 0;
  164. char name [80];
  165. GOODWILL_TRUCK* truckptr;
  166. cout << "\nPlease enter the id number: ";
  167. cin >> id_num;
  168. cin.ignore(81, '\n');
  169. cout << "\nPlease enter the truck name: ";
  170. cin.getline(name, 80);
  171. cout << "\nPlease enter the amount of donations in truck: ";
  172. cin >> donations;
  173. cin.ignore(81, '\n');
  174. clrscr();
  175. truckptr = new GOODWILL_TRUCK (id_num, name, donations);
  176. cout << "\n\n\Trucks in inventory: " << truckptr->TOTAL_TRUCKS();
  177. return truckptr;
  178. }
  179. void display (GOODWILL_TRUCK& truck)
  180. {
  181. cout << "\nTruck ID " << truck.GET_ID_NUM();
  182. cout << "\nName of Truck: " << truck.GET_NAME();
  183. cout << "\nTruck Capacity: " << truck.GET_CAP();
  184. cout << "\nDonations on Hand: " << truck.GET_CONT();
  185. }
Apr 22 '10 #1

✓ answered by hype261

If you don't have a book on the STL I would recommend you picking one up. The C++ Standard Library by Nicolai Josuttis is a good reference to have.

Another good reference for the stl map is here. It will give you code examples so you can modify them for your needs.

http://www.cplusplus.com/reference/stl/map/

James

3 1932
hype261
207 100+
If I were you I would consider picking either Truck Name or ID as your unique identifier for your trucks. That way you could use the stl map container to store the unique keys and values.
Apr 22 '10 #2
@hype261
Ok, working on that, then can you help me with entering truck number to where it will remember them
Apr 22 '10 #3
hype261
207 100+
If you don't have a book on the STL I would recommend you picking one up. The C++ Standard Library by Nicolai Josuttis is a good reference to have.

Another good reference for the stl map is here. It will give you code examples so you can modify them for your needs.

http://www.cplusplus.com/reference/stl/map/

James
Apr 22 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Peter Blum | last post by:
I have built an assembly (dll) from which I expect third parties to subclass. As a result, when my assembly has a version change, it will cause any third party assembly based on it to break unless...
1
by: Jens Körte | last post by:
Hi NG! I encountered some strange behaviour when using focus() I use a form with several input-fields. A user can enter stuff. After entering I want to check the value, i.e. that a number is...
687
by: cody | last post by:
no this is no trollposting and please don't get it wrong but iam very curious why people still use C instead of other languages especially C++. i heard people say C++ is slower than C but i can't...
6
by: damian birchler | last post by:
If I run the following I get a segmentation fault: #define NAMELEN 15 #define NPERS 10 typedef struct pers { char name; int money; } pers_t;
7
by: Mr. Mountain | last post by:
In the following code I simulate work being done on different threads by sleeping a couple methods for about 40 ms. However, some of these methods that should finish in about 40 -80 ms take as long...
0
by: Jenny | last post by:
Hi all I've problems with forms authentication. I'm using a simple function on the login.aspx page: Private Sub LoginButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)...
9
suzee_q00
by: suzee_q00 | last post by:
I will admit that lots of times the obvious eludes me and this is most likely one of those times but if anyone has any ideas on what I can do to make this code work, I would greatly appreciate it....
1
by: kashif456 | last post by:
I can't figure out why I am getting error updating, deleting and inserting new rows. I am amble to get my dataview populated and also detailview populated: Here's my code: <%@ Page...
3
by: dtvuser | last post by:
Hi, I'm new to PHP and seem to be having soom problems, I'm getting confused with all the different styles of script writing. I've created a PHP script to submit details to my email but the...
2
by: rustyc | last post by:
Well, here's my first post in this forum (other than saying 'HI' over in the hi forum ;-) As I said over there: ... for a little side project at home, I'm writing a ham radio web site in...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.