Array problem...

Reply

Join Date: Feb 2008
Posts: 59
Reputation: nelledawg is an unknown quantity at this point 
Solved Threads: 0
nelledawg nelledawg is offline Offline
Junior Poster in Training

Array problem...

 
0
  #1
Mar 7th, 2008
Hi guys,

Ok so once again, I have pretty much the whole code written, but something is not working right! When I run it and select "add record", it works up until the user inputs price, then it just prints a ton of numbers and basically crashes. Please help me figure out what is wrong!

Here is the code:

  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <stdlib.h>
  4.  
  5. // ** Prototypes **
  6. void heading(void);
  7. int menu();
  8. int add();
  9. int getint(int min, int max, char prompt[]);
  10. double getreal(double min, double max, char prompt[]);
  11. double total(double quantity, double amount);
  12. double profit(double profit_cost, double profit_price);
  13. double init_costs(double t[], int x);
  14. double show_costs(double t[], int x);
  15. void show(int prodnum, int prodtype, int prodquan, double cost, double price, double prod_price, double prod_cost, double prod_profit);
  16. int menuerror(int min, int max, char prompt[]);
  17. int prompt(char msg[]);
  18. int quit(void);
  19. void message(char msg[]);
  20.  
  21.  
  22. // ** Functions **
  23. int main()
  24. {
  25. int TRUE = 1;
  26. int FALSE = 0;
  27. int select, end = TRUE;
  28.  
  29. do
  30. {
  31.  
  32. select = menu();
  33. switch (select)
  34. {
  35. case 1: add(); break;
  36. case 2:
  37. case 3:
  38. case 4:
  39. case 5: end = quit(); break;
  40. default: message("\n\nPlease make a selection between 1 and 5.\a");
  41. }
  42. }
  43.  
  44. while (end);
  45. return 0;
  46. }
  47. /* ================================================================ */
  48.  
  49. int menu()
  50. {
  51. int choice;
  52. system("cls");
  53.  
  54. printf("Sierra Sporting Goods\n\n");
  55. printf("1 = Add a record\n");
  56. printf("2 = Report\n");
  57. printf("3 = Delete a record\n");
  58. printf("4 = Change a record\n");
  59. printf("5 = Quit\n");
  60. choice = menuerror(1, 5, "Enter your selection ");
  61.  
  62. return(choice);
  63. }
  64. /* ================================================================ */
  65.  
  66. void heading()
  67. {
  68. system("cls");
  69. printf("Sierra Sporting Goods\n\n\n");
  70. return;
  71. }
  72. /* ================================================================ */
  73.  
  74. int add()
  75. {
  76. double cost, price, prod_cost, prod_price, prod_profit;
  77. double MINCOST = 5.00;
  78. double MAXCOST = 900.00;
  79. double MINPRICE = 6.00;
  80. double types[6];
  81. double MAXPRICE = 1000.00;
  82. int prodnum, prodtype, prodquan;
  83. int MINPROD = 1;
  84. int MAXPROD = 9999;
  85. int MINTYPE = 1;
  86. int MAXTYPE = 5;
  87. int MINQUAN = 1;
  88. int MAXQUAN = 50;
  89. char choice;
  90.  
  91. system("cls");
  92.  
  93. init_costs(types, 6);
  94. do
  95. {
  96. heading();
  97.  
  98. prodnum = getint(MINPROD, MAXPROD, "product number");
  99. prodtype = getint(MINTYPE, MAXTYPE, "product type");
  100. prodquan = getint(MINQUAN, MAXQUAN, "product quantity");
  101. cost = getreal(MINCOST, MAXCOST, "product cost");
  102.  
  103. types[prodtype] += cost;
  104.  
  105. price = getreal(MINPRICE, MAXPRICE, "product price");
  106. prod_cost = total(prodquan, cost);
  107. prod_price = total(prodquan, price);
  108. prod_profit = profit(prod_price, prod_cost);
  109. show(prodnum, prodtype, prodquan, cost, price, prod_price, prod_cost, prod_profit);
  110. show_costs(types, 6);
  111. choice = prompt("Would you like to continue");
  112. }
  113. while (choice != 'N');
  114. return (choice);
  115. }
  116. /* ================================================================ */
  117.  
  118. int getint(int min, int max, char item[])
  119. {
  120. int x;
  121. printf("Enter a %s between %d and %d: ", item, min, max);
  122. scanf("%d%*c", &x);
  123. while (x < min || x > max)
  124. {
  125. message("\nError in range\a");
  126. printf("Enter a %s between %d and %d: ", item, min, max);
  127. scanf("%d%*c", &x);
  128. }
  129. return(x);
  130. }
  131. /* ================================================================ */
  132.  
  133. double getreal(double min, double max, char item[])
  134. {
  135. double y;
  136.  
  137. printf("Enter a %s between $%.2lf and $%.2lf: ", item, min, max);
  138. scanf("%lf%*c", &y);
  139. while (y < min || y > max)
  140. {
  141. message("\nError in range. Press Enter to continue.S\a");
  142. printf("Enter a %s between $%.2lf and $%.2lf: ", item, min, max);
  143. scanf("%lf%*c", &y);
  144. }
  145. return(y);
  146. }
  147. /* ================================================================ */
  148.  
  149. double total(double quantity, double amount)
  150. {
  151. return (quantity * amount);
  152. }
  153. /* ================================================================ */
  154.  
  155. double profit(double profit_price, double profit_cost)
  156. {
  157. return (profit_price - profit_cost);
  158. }
  159. /* ================================================================ */
  160.  
  161. double init_costs(double t[], int x)
  162. {
  163. int z;
  164.  
  165. for (z = 1; z < x; z++)
  166. t[z] = 0;
  167.  
  168. return 0;
  169. }
  170. /* ================================================================ */
  171.  
  172. double show_costs(double t[], int x)
  173. {
  174. int z;
  175. double total = 0;
  176.  
  177. printf("Product Cost by Type\n\n");
  178. printf("Type Cost\n\n");
  179. for (z = 1; z < x; t++)
  180. {
  181. printf("%d%lf\n", z, t[z]);
  182. total += t[z];
  183. }
  184. printf("%22.2lf\n", total);
  185.  
  186. return 0;
  187. }
  188. /* ================================================================ */
  189. void message(char msg[])
  190. {
  191. printf("%s\n\n", msg);
  192. getchar();
  193. }
  194. /* ================================================================ */
  195.  
  196. int prompt(char msg[])
  197. {
  198. int z;
  199. do
  200. {
  201. printf("%s (Y/N)? ", msg);
  202. z = toupper(getchar());
  203. if (z != 'Y' && z != 'N') printf("\nError, please enter Y or N only.\n");
  204. }
  205. while (z != 'Y' && z != 'N');
  206. return(z);
  207. }
  208. /* ================================================================ */
  209.  
  210. int quit()
  211. {
  212. int TRUE = 1;
  213. int FALSE = 0;
  214. int z, end = TRUE;
  215.  
  216. z = prompt("\nEnd program");
  217. if (z == 'Y')
  218. {
  219. system("cls");
  220. message("\nSierra Sporting Goods Database closed successfully.");
  221. end = FALSE;
  222. }
  223. return(end);
  224. }
  225. /* ================================================================ */
  226.  
  227. int menuerror(int min, int max, char item[])
  228. {
  229. int z;
  230. printf("%s from %d to %d: ", item, min, max);
  231. scanf("%d%*c", &z);
  232. while (z < min || z > max)
  233. {
  234. message("\nError in range. Press Enter to continue.\a");
  235. printf("%s from %d to %d: ", item, min, max);
  236. scanf("%d%*c", &z);
  237. }
  238. return(z);
  239. }
  240. /* ================================================================ */
  241. void show(int prodnum, int prodtype, int prodquan, double cost, double price,
  242. double prod_price, double prod_cost, double prod_profit)
  243. {
  244.  
  245. printf("\n\n\nThe product number is ----> %04d\n", prodnum);
  246. printf("The product type is ------> %d\n", prodtype);
  247. printf("The quantity is ----------> %d\n", prodquan);
  248. printf("The cost is --------------> $%.2lf\n", cost);
  249. printf("The price is -------------> $%.2lf\n\n", price);
  250.  
  251. printf("Total product price ------> $%.2lf\n", prod_price);
  252. printf("Total product cost -------> $%.2lf\n", prod_cost);
  253. printf("Total product profit -----> $%.2lf\n\n\n\n", prod_profit);
  254.  
  255. return;
  256. }
  257. /* ================================================================ */
Last edited by nelledawg; Mar 7th, 2008 at 7:41 pm.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,752
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 491
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Array problem...

 
0
  #2
Mar 7th, 2008
Look at line 179. I am guessing it is crashing here.

  1. for (z = 1; z < x; t++)
Do you want to increment t or z?
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 59
Reputation: nelledawg is an unknown quantity at this point 
Solved Threads: 0
nelledawg nelledawg is offline Offline
Junior Poster in Training

Re: Array problem...

 
0
  #3
Mar 7th, 2008
Yeah, I saw that and fixed it. Here is the code I have now... I run the program and it goes all the way through the first show() function, then at the continue prompt I press 'n' and it shows the show_costs table (which is completely not working btw), but it also shows the Menu in the same window again and I just want to have a "Press ENTER to continue" prompt after the show_costs table that will take the user back to the menu. Pleaaaase help me I'm running out of steam and I need to get it done or it's going to drive me crazy!

Here is the code:

  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <stdlib.h>
  4.  
  5. // ** Prototypes **
  6. void heading(void);
  7. int menu();
  8. int add();
  9. int getint(int min, int max, char prompt[]);
  10. double getreal(double min, double max, char prompt[]);
  11. double total(double quantity, double amount);
  12. double profit(double profit_cost, double profit_price);
  13. void init_costs(double t[], int x);
  14. void show_costs(double t[], int x);
  15. void show(int prodnum, int prodtype, int prodquan, double cost, double price, double prod_price, double prod_cost, double prod_profit);
  16. int menuerror(int min, int max, char prompt[]);
  17. int prompt(char msg[]);
  18. int quit(void);
  19. void message(char msg[]);
  20.  
  21.  
  22. // ** Functions **
  23. int main()
  24. {
  25. int TRUE = 1;
  26. int FALSE = 0;
  27. int select, end = TRUE;
  28.  
  29. do
  30. {
  31.  
  32. select = menu();
  33. switch (select)
  34. {
  35. case 1: add(); break;
  36. case 2:
  37. case 3:
  38. case 4:
  39. case 5: end = quit(); break;
  40. default: message("\n\nPlease make a selection between 1 and 5.\a");
  41. }
  42. }
  43.  
  44. while (end);
  45. return 0;
  46. }
  47. /* ================================================================ */
  48.  
  49. int menu()
  50. {
  51. int choice;
  52.  
  53. printf("Sierra Sporting Goods\n\n");
  54. printf("1 = Add a record\n");
  55. printf("2 = Report\n");
  56. printf("3 = Delete a record\n");
  57. printf("4 = Change a record\n");
  58. printf("5 = Quit\n\n");
  59. choice = menuerror(1, 5, "Enter your selection");
  60.  
  61. return(choice);
  62. }
  63. /* ================================================================ */
  64.  
  65. void heading()
  66. {
  67. system("cls");
  68. printf("Sierra Sporting Goods\n\n\n");
  69. return;
  70. }
  71. /* ================================================================ */
  72.  
  73. int add()
  74. {
  75. double cost, price, prod_cost, prod_price, prod_profit;
  76. double MINCOST = 5.00;
  77. double MAXCOST = 900.00;
  78. double MINPRICE = 6.00;
  79. double MAXPRICE = 1000.00;
  80. int prodnum, prodtype, prodquan;
  81. int MINPROD = 1;
  82. int MAXPROD = 9999;
  83. int MINTYPE = 1;
  84. int MAXTYPE = 5;
  85. int MINQUAN = 1;
  86. int MAXQUAN = 50;
  87. double types[6];
  88. char choice;
  89.  
  90.  
  91. init_costs(types, 6);
  92. do
  93. {
  94. heading();
  95.  
  96. prodnum = getint(MINPROD, MAXPROD, "product number");
  97. prodtype = getint(MINTYPE, MAXTYPE, "product type");
  98. prodquan = getint(MINQUAN, MAXQUAN, "product quantity");
  99. cost = getreal(MINCOST, MAXCOST, "product cost");
  100. price = getreal(MINPRICE, MAXPRICE, "product price");
  101.  
  102. types[prodtype] += cost;
  103.  
  104. prod_cost = total(prodquan, cost);
  105. prod_price = total(prodquan, price);
  106. prod_profit = profit(prod_price, prod_cost);
  107. show(prodnum, prodtype, prodquan, cost, price, prod_price, prod_cost, prod_profit);
  108. choice = prompt("Would you like to continue");
  109. }
  110. while (choice != 'N');
  111. getchar();
  112. show_costs(types, 6);
  113.  
  114.  
  115.  
  116. return 0;
  117. }
  118. /* ================================================================ */
  119.  
  120. int getint(int min, int max, char item[])
  121. {
  122. int x;
  123. printf("Enter a %s between %d and %d: ", item, min, max);
  124. scanf("%d%*c", &x);
  125. while (x < min || x > max)
  126. {
  127. message("\nError in range. Press Enter to continue.\a");
  128. printf("Enter a %s between %d and %d: ", item, min, max);
  129. scanf("%d%*c", &x);
  130. }
  131. return(x);
  132. }
  133. /* ================================================================ */
  134.  
  135. double getreal(double min, double max, char item[])
  136. {
  137. double y;
  138.  
  139. printf("Enter a %s between $%.2lf and $%.2lf: ", item, min, max);
  140. scanf("%lf%*c", &y);
  141. while (y < min || y > max)
  142. {
  143. message("\nError in range. Press Enter to continue.\a");
  144. printf("Enter a %s between $%.2lf and $%.2lf: ", item, min, max);
  145. scanf("%lf%*c", &y);
  146. }
  147. return(y);
  148. }
  149. /* ================================================================ */
  150.  
  151. double total(double quantity, double amount)
  152. {
  153. return (quantity * amount);
  154. }
  155. /* ================================================================ */
  156.  
  157. double profit(double profit_price, double profit_cost)
  158. {
  159. return (profit_price - profit_cost);
  160. }
  161. /* ================================================================ */
  162.  
  163. void init_costs(double t[], int x)
  164. {
  165. int z;
  166.  
  167. for (z = 1; z < x; z++)
  168. t[z] = 0;
  169.  
  170. }
  171. /* ================================================================ */
  172.  
  173. void show_costs(double t[], int x)
  174. {
  175. int z;
  176. double total = 0;
  177.  
  178. system("cls");
  179.  
  180. printf("Product Cost by Type\n\n");
  181. printf("Type Cost\n\n");
  182. for (z = 1; z < x; z++)
  183. {
  184. printf("%2d%20.2lf\n", t[z], z);
  185. total += t[z];
  186. }
  187. printf("%22.2lf\n\n", total);
  188. printf("Press Enter to continue.\a");
  189.  
  190. }
  191. /* ================================================================ */
  192. void message(char msg[])
  193. {
  194. printf("%s\n\n", msg);
  195. }
  196. /* ================================================================ */
  197.  
  198. int prompt(char msg[])
  199. {
  200. int z;
  201. do
  202. {
  203. printf("%s (Y/N)? ", msg);
  204. z = toupper(getchar());
  205. if (z != 'Y' && z != 'N') printf("\nError, please enter Y or N only.\n");
  206. }
  207. while (z != 'Y' && z != 'N');
  208. return(z);
  209. }
  210. /* ================================================================ */
  211.  
  212. int quit()
  213. {
  214. int TRUE = 1;
  215. int FALSE = 0;
  216. int z, end = TRUE;
  217.  
  218. z = prompt("\nEnd program");
  219. if (z == 'Y')
  220. {
  221. system("cls");
  222. message("\nSierra Sporting Goods Database closed successfully.");
  223. end = FALSE;
  224. }
  225. return(end);
  226. }
  227. /* ================================================================ */
  228.  
  229. int menuerror(int min, int max, char item[])
  230. {
  231. int z;
  232. printf("%s from %d to %d: ", item, min, max);
  233. scanf("%d%*c", &z);
  234. while (z < min || z > max)
  235. {
  236. message("\nError in range. Press Enter to continue.\a");
  237. printf("%s from %d to %d: ", item, min, max);
  238. scanf("%d%*c", &z);
  239. }
  240. return(z);
  241. }
  242. /* ================================================================ */
  243. void show(int prodnum, int prodtype, int prodquan, double cost, double price,
  244. double prod_price, double prod_cost, double prod_profit)
  245. {
  246.  
  247. printf("\n\n\nThe product number is ----> %04d\n", prodnum);
  248. printf("The product type is ------> %d\n", prodtype);
  249. printf("The quantity is ----------> %d\n", prodquan);
  250. printf("The cost is --------------> $%.2lf\n", cost);
  251. printf("The price is -------------> $%.2lf\n\n", price);
  252.  
  253. printf("Total product price ------> $%.2lf\n", prod_price);
  254. printf("Total product cost -------> $%.2lf\n", prod_cost);
  255. printf("Total product profit -----> $%.2lf\n\n\n\n", prod_profit);
  256.  
  257. return;
  258. }
  259. /* ================================================================ */
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,149
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1435
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Array problem...

 
0
  #4
Mar 7th, 2008
line 189: add getchar() to make the program stop and wait for input.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 59
Reputation: nelledawg is an unknown quantity at this point 
Solved Threads: 0
nelledawg nelledawg is offline Offline
Junior Poster in Training

Re: Array problem...

 
0
  #5
Mar 7th, 2008
Alright, I got it! Thanks a lot for your help, guys!

Here is the working code:

  1.  
  2.  
  3. #include <stdio.h>
  4. #include <ctype.h>
  5. #include <stdlib.h>
  6.  
  7. // ** Prototypes **
  8. void heading(void);
  9. int menu();
  10. int add();
  11. int getint(int min, int max, char prompt[]);
  12. double getreal(double min, double max, char prompt[]);
  13. double total(double quantity, double amount);
  14. double profit(double profit_cost, double profit_price);
  15. void init_costs(double t[], int x);
  16. void show_costs(double t[], int x);
  17. void show(int prodnum, int prodtype, int prodquan, double cost, double price, double prod_price, double prod_cost, double prod_profit);
  18. int menuerror(int min, int max, char prompt[]);
  19. int prompt(char msg[]);
  20. int quit(void);
  21. void message(char msg[]);
  22.  
  23.  
  24. // ** Functions **
  25. int main()
  26. {
  27. int TRUE = 1;
  28. int FALSE = 0;
  29. int select, end = TRUE;
  30.  
  31. do
  32. {
  33.  
  34. select = menu();
  35. switch (select)
  36. {
  37. case 1: add(); break;
  38. case 2:
  39. case 3:
  40. case 4:
  41. case 5: end = quit(); break;
  42. default: message("\n\nPlease make a selection between 1 and 5.\a");
  43. }
  44. }
  45.  
  46. while (end);
  47. return 0;
  48. }
  49. /* ================================================================ */
  50.  
  51. int menu()
  52. {
  53. int choice;
  54.  
  55. system("cls");
  56.  
  57. printf("Sierra Sporting Goods\n\n");
  58. printf("1 = Add a record\n");
  59. printf("2 = Report\n");
  60. printf("3 = Delete a record\n");
  61. printf("4 = Change a record\n");
  62. printf("5 = Quit\n\n");
  63. choice = menuerror(1, 5, "Enter your selection");
  64.  
  65. return(choice);
  66. }
  67. /* ================================================================ */
  68.  
  69. void heading()
  70. {
  71. system("cls");
  72. printf("Sierra Sporting Goods\n\n\n");
  73. return;
  74. }
  75. /* ================================================================ */
  76.  
  77. int add()
  78. {
  79. double cost, price, prod_cost, prod_price, prod_profit;
  80. double MINCOST = 5.00;
  81. double MAXCOST = 900.00;
  82. double MINPRICE = 6.00;
  83. double MAXPRICE = 1000.00;
  84. int prodnum, prodtype, prodquan;
  85. int MINPROD = 1;
  86. int MAXPROD = 9999;
  87. int MINTYPE = 1;
  88. int MAXTYPE = 5;
  89. int MINQUAN = 1;
  90. int MAXQUAN = 50;
  91. double types[6];
  92. char choice;
  93.  
  94.  
  95. init_costs(types,6);
  96. do
  97. {
  98. heading();
  99.  
  100. prodnum = getint(MINPROD, MAXPROD, "product number");
  101. prodtype = getint(MINTYPE, MAXTYPE, "product type");
  102. prodquan = getint(MINQUAN, MAXQUAN, "product quantity");
  103. cost = getreal(MINCOST, MAXCOST, "product cost");
  104. price = getreal(MINPRICE, MAXPRICE, "product price");
  105. prod_cost = total(prodquan, cost);
  106. prod_price = total(prodquan, price);
  107. prod_profit = profit(prod_price, prod_cost);
  108.  
  109. types[prodtype] += prod_cost;
  110.  
  111. show(prodnum, prodtype, prodquan, cost, price, prod_price, prod_cost, prod_profit);
  112. choice = prompt("Would you like to enter another product");
  113. }
  114. while (choice != 'N');
  115. getchar();
  116. show_costs(types,6);
  117.  
  118.  
  119.  
  120. return 0;
  121. }
  122. /* ================================================================ */
  123.  
  124. int getint(int min, int max, char item[])
  125. {
  126. int x;
  127. printf("Enter a %s between %d and %d: ", item, min, max);
  128. scanf("%d%*c", &x);
  129. while (x < min || x > max)
  130. {
  131. message("\nError in range. Press Enter to continue.\a");
  132. printf("Enter a %s between %d and %d: ", item, min, max);
  133. scanf("%d%*c", &x);
  134. }
  135. return(x);
  136. }
  137. /* ================================================================ */
  138.  
  139. double getreal(double min, double max, char item[])
  140. {
  141. double y;
  142.  
  143. printf("Enter a %s between $%.2lf and $%.2lf: ", item, min, max);
  144. scanf("%lf%*c", &y);
  145. while (y < min || y > max)
  146. {
  147. message("\nError in range. Press Enter to continue.\a");
  148. printf("Enter a %s between $%.2lf and $%.2lf: ", item, min, max);
  149. scanf("%lf%*c", &y);
  150. }
  151. return(y);
  152. }
  153. /* ================================================================ */
  154.  
  155. double total(double quantity, double amount)
  156. {
  157. return (quantity * amount);
  158. }
  159. /* ================================================================ */
  160.  
  161. double profit(double profit_price, double profit_cost)
  162. {
  163. return (profit_price - profit_cost);
  164. }
  165. /* ================================================================ */
  166.  
  167. void init_costs(double t[], int x)
  168. {
  169. int z;
  170.  
  171. for (z = 1; z < x; z++)
  172. t[z] = 0;
  173.  
  174. }
  175. /* ================================================================ */
  176.  
  177. void show_costs(double t[], int x)
  178. {
  179. int z;
  180. double total = 0;
  181.  
  182. system("cls");
  183.  
  184. printf(" Product Cost by Type\n\n");
  185. printf("_Type_____________Cost_\n\n");
  186. for (z = 1; z < x; z++)
  187. {
  188. printf(" %2d%20.2lf\n", z, t[z]);
  189. total += t[z];
  190. }
  191. printf("________________________\n");
  192. printf("%23.2lf\n\n\n\n", total);
  193. printf("Press ENTER to return to the Main Menu...");
  194. getchar();
  195.  
  196.  
  197. }
  198. /* ================================================================ */
  199. void message(char msg[])
  200. {
  201. printf("%s\n\n", msg);
  202. }
  203. /* ================================================================ */
  204.  
  205. int prompt(char msg[])
  206. {
  207. int z;
  208. do
  209. {
  210. printf("%s (Y/N)? ", msg);
  211. z = toupper(getchar());
  212. if (z != 'Y' && z != 'N') printf("\nError, please enter Y or N only.\n");
  213. }
  214. while (z != 'Y' && z != 'N');
  215. return(z);
  216. }
  217. /* ================================================================ */
  218.  
  219. int quit()
  220. {
  221. int TRUE = 1;
  222. int FALSE = 0;
  223. int z, end = TRUE;
  224.  
  225. z = prompt("\nEnd program\a");
  226. if (z == 'Y')
  227. {
  228. system("cls");
  229. message("\nSierra Sporting Goods Database closed successfully.");
  230. end = FALSE;
  231. }
  232. return(end);
  233. }
  234. /* ================================================================ */
  235.  
  236. int menuerror(int min, int max, char item[])
  237. {
  238. int z;
  239. printf("%s from %d to %d: ", item, min, max);
  240. scanf("%d%*c", &z);
  241. while (z < min || z > max)
  242. {
  243. message("\nError in range. Press Enter to continue.\a");
  244. printf("%s from %d to %d: ", item, min, max);
  245. scanf("%d%*c", &z);
  246. }
  247. return(z);
  248. }
  249. /* ================================================================ */
  250. void show(int prodnum, int prodtype, int prodquan, double cost, double price,
  251. double prod_price, double prod_cost, double prod_profit)
  252. {
  253.  
  254. printf("\n\n\nThe product number is ----> %04d\n", prodnum);
  255. printf("The product type is ------> %d\n", prodtype);
  256. printf("The quantity is ----------> %d\n", prodquan);
  257. printf("The cost is --------------> $%.2lf\n", cost);
  258. printf("The price is -------------> $%.2lf\n\n", price);
  259.  
  260. printf("Total product price ------> $%.2lf\n", prod_price);
  261. printf("Total product cost -------> $%.2lf\n", prod_cost);
  262. printf("Total product profit -----> $%.2lf\n\n\n\n", prod_profit);
  263.  
  264. return;
  265. }
  266. /* ================================================================ */
Last edited by nelledawg; Mar 7th, 2008 at 10:54 pm. Reason: SOLVED IT!!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,149
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1435
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: Array problem...

 
0
  #6
Mar 7th, 2008
>>it isn't giving the total cost (cost * prodquan), just the cost that the user entered. I'm so close!

what function? [edit]nevermind you already told me that [/edit]

line 186: you didn't tell the program to print that information. You have to add it to your program.
Last edited by Ancient Dragon; Mar 7th, 2008 at 10:56 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: Array problem...

 
0
  #7
Mar 7th, 2008
Please explain this line: scanf("%lf%*c", &y); It makes no sense with the format specifier you have.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
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