Help please

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

Join Date: Oct 2006
Posts: 4
Reputation: mlawson22 is an unknown quantity at this point 
Solved Threads: 0
mlawson22 mlawson22 is offline Offline
Newbie Poster

Help please

 
0
  #1
Oct 8th, 2006
Im so lost in this C++ class I have a vague idea of what to do but am getting myself confused. If anyone would help me get started on doing this assignment I would greatly appreciate it.

Assignment:
A mail order house sells five different products whose retail prices are : product-1 $2.98, product2- $4.50, product3- $9.98, product4- $4.49, and product5- $6.87. Write a program that reads a series of pairs of numbers as follows:
a) product number
b) quantity sold

Your program should use a switch statement to determine the retail price for each product. Your program should calculate and display the total calue of all products sold. Use a sentinel-controlled loop to determine when the program should stop looping and display the final results.

I have completley no idea how to even start writing this program if anyone could please help me I would appreciate it.

thnx
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,649
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 474
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Help please

 
0
  #2
Oct 8th, 2006
Try to come up with atleast something. This forum is for asking help when you get stuck.

Basic Structure:
1. Create the necessary variables.
2. Create a while loop which keeps on asking user for input and ask him a option at the end whether he wants to continue or not.
3. After exitting the user input phase, keep a switch statement.
4. Display and Exit
I don't accept change; I don't deserve to live.

Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 4
Reputation: mlawson22 is an unknown quantity at this point 
Solved Threads: 0
mlawson22 mlawson22 is offline Offline
Newbie Poster

Re: Help please

 
0
  #3
Oct 8th, 2006
This is what I have tried to come up with I believe some of it is correct but not sure if I have codded it correctly.

  1. #include "stdafx.h"
  2. #include <iostream>
  3. using std::cout;
  4. using std::cin;
  5. using std::endl;
  6.  
  7. #include "Ch5.h"
  8.  
  9.  
  10.  
  11. cout << "Product A value $2.98" << endl;
  12. cout << "Product B value $4.50" << endl;
  13. cout << "Product C value $9.98" << endl;
  14. cout << "Product D value $4.49" << endl;
  15. cout << "Product E value $6.87" << endl;
  16. cout << " " << endl;
  17.  
  18. A== $2.98;
  19. B== $4.50;
  20. C== $9.98;
  21. D== $4.49;
  22. E== $6.87;
  23.  
  24. do
  25. {
  26. cout << "Enter total sold of product A";
  27. cin >> Atotal;
  28. cout << "Enter total sold of product B";
  29. cin >> Btotal;
  30. cout << "Enter total sold of product C";
  31. cin << Ctotal;
  32. cout << "Enter total sold of product D";
  33. cin >> Dtotal;
  34. cout << "Enter total sold of product E";
  35. cin >> Etotal;
  36. cout << "Enter 1 to quit";
  37. cin >> 1 >> endl;
  38.  
  39. switch (actual retail price)
  40. {
  41. case 'A':
  42. case 'a':
  43.  
  44. cout << "Product A retail value" <<endl;
  45. cin >> A retail; >>endl;
  46. break;
  47.  
  48. case 'B':
  49. case 'b':
  50.  
  51. cout << "Product B retail value" << endl;
  52. cin >> B retail; >> endl;
  53. break;
  54.  
  55. case 'C':
  56. case 'c':
  57.  
  58. cout << "Product C retail value" << endl;
  59. cin >> C retail; >> endl;
  60. break;
  61.  
  62. case 'D':
  63. case 'd':
  64.  
  65. cout << "Product D retail value" << endl;
  66. cin >> D retail; >> endl;
  67. break;
  68.  
  69. case 'E':
  70. case 'e':
  71.  
  72. cout << "Product E retail value" << endl;
  73. cin >> E retail; >> endl;
  74.  
  75. case '1':
  76.  
  77. cout << "Good bye" << endl;
  78. break;
  79. }

Im not looking for someone to do my homework didnt mean to come across like that, I was working on typing the code when I came across this site. I want to learn this stuff its just I am having a extremely hard time understanding it, I am taking it as an internet course and realize now I shouldnt have. A few other things I am confused of are how to write header files and having multiple .cpp files in a program if someone could direct me to some literature that explains this I would appreciate it thnx.
Last edited by ~s.o.s~; Oct 8th, 2006 at 1:58 pm. Reason: Added code tags, learn to use them yourself
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,649
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 474
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Help please

 
0
  #4
Oct 8th, 2006
Please use code tags to make your code more readable.

Also which compiler are you using, which OS and all that...

[EDIT] I think there is some kind of logic error in your code. YOu are asked to read the pair of numbers product number and quantity sold and you just ask the user for the total number of items sold.

Also what does this:
  1. A== $2.98;
  2. B== $4.50;
  3. C== $9.98;
  4. D== $4.49;
  5. E== $6.87;
Stand for ?


Also this stmt is incorrect
  1.  
  2. cin >> C retail; >> endl;
Try to compile your code and see the plethora of errors it gives.
Last edited by ~s.o.s~; Oct 8th, 2006 at 2:05 pm.
I don't accept change; I don't deserve to live.

Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 4
Reputation: mlawson22 is an unknown quantity at this point 
Solved Threads: 0
mlawson22 mlawson22 is offline Offline
Newbie Poster

Re: Help please

 
0
  #5
Oct 8th, 2006
Sorry for not posting it correctly. Im using Windows XP Home ed. Compiler is Microsoft Visual Studio .NET 2003. We are supposed to use Win32 file types in it aswell if that helps any.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,127
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: 283
Moderator
WaltP's Avatar
WaltP WaltP is online now Online
Posting Sensei

Re: Help please

 
0
  #6
Oct 8th, 2006
Where did you take the total sold and calculate the total price? Shouldn't that be in each case statement?

Also, at the beginning of your do loop, you should ask only 2 questions:
1) What product was sold (A-E):
2) How many sold:
The your switch value would be the product and the case calculates the total.
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  
Join Date: Oct 2006
Posts: 4
Reputation: mlawson22 is an unknown quantity at this point 
Solved Threads: 0
mlawson22 mlawson22 is offline Offline
Newbie Poster

Re: Help please

 
0
  #7
Oct 8th, 2006
Ok been working on this thing for quite some time now this is what I have came up with from the input you all gave me and thank you for the help by the way.

  1. #include "stdafx.h"
  2. #include <iostream>
  3. using std::cout;
  4. using std::cin;
  5. using std::endl;
  6.  
  7. #include "Ch5.12.h"
  8.  
  9. //
  10. //
  11. ProductSales::ProductSales( string name )
  12. {
  13. setProductName( name );
  14. aCount = 0;
  15. bCount = 0;
  16. cCount = 0;
  17. dCount = 0;
  18. eCount = 0;
  19. }
  20.  
  21. void ProductSales::inputSales
  22. {
  23. int sales;
  24.  
  25. cout << "Enter each products total sales. " << endl
  26. << "Enter -1 to end input." << endl;
  27. }
  28.  
  29.  
  30. int; ( A == $2.98 );
  31. int; ( B == $4.50 );
  32. int; ( C == $9.98 );
  33. int; ( D == $4.49 );
  34. int ( E == $6.87 );
  35.  
  36.  
  37. do
  38. {
  39. cout << "What product sold A-E" << endl;
  40. cout << "How many sold of each" << endl;
  41. while ( product != -1 ) //end of file char
  42. {
  43.  
  44. switch (product)
  45. {
  46. case 'A':
  47. case 'a':
  48.  
  49. cout << "A total sales" <<endl;
  50. cin >> A sales; >>endl;
  51. break;
  52.  
  53. case 'B':
  54. case 'b':
  55.  
  56. cout << "B total sales" << endl;
  57. cin >> B sales; >> endl;
  58. break;
  59.  
  60. case 'C':
  61. case 'c':
  62.  
  63. cout << "C total sales" << endl;
  64. cin >> C sales; >> endl;
  65. break;
  66.  
  67. case 'D':
  68. case 'd':
  69.  
  70. cout << "D total sales" << endl;
  71. cin >> D sales; >> endl;
  72. break;
  73.  
  74. case 'E':
  75. case 'e':
  76.  
  77. cout << "E total sales" << endl;
  78. cin >> E sales; >> endl;
  79.  
  80. case '-1':
  81.  
  82. cout << "Good bye" << endl;
  83. break;
  84. }
  85. }
  86. }
  87.  
  88. void ProductSales::displayProductSales
  89. {
  90. cout << "\nA: " << aCount // displays Product A sales
  91. << "\nB: " << bCount // displays Product B sales
  92. << "\nC: " << cCount // displays Product C sales
  93. << "\nD: " << dCount // displays Product D sales
  94. << "\nE: " << eCount // displays Product E sales
  95. << endl; // ends the function display Product sales
  96. }

Here is the header file.

  1. #include <string>
  2. using std::string;
  3.  
  4.  
  5. class ProductSales
  6. {
  7. public:
  8. ProductSales( string );
  9. void setProductName();
  10. void inputSales();
  11. void displayProductSales
  12. private:
  13. string productName
  14. int aCount;
  15. int bCount;
  16. int cCount;
  17. int dCount;
  18. int eCount;
  19. };

That is what I have came up with from taking what you all told me and getting some examples from the book, but I am still getting a butt load of errors. Any hints or tips would be greatly appreciated since this project was due yesterday
Last edited by mlawson22; Oct 8th, 2006 at 9:34 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,127
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: 283
Moderator
WaltP's Avatar
WaltP WaltP is online now Online
Posting Sensei

Re: Help please

 
0
  #8
Oct 9th, 2006
Originally Posted by mlawson22 View Post
Ok been working on this thing for quite some time now this is what I have came up with from the input you all gave me and thank you for the help by the way.

...

That is what I have came up with from taking what you all told me and getting some examples from the book, but I am still getting a butt load of errors.
Doesn't surprise me.

  1. #include "stdafx.h" //// What's this statement do for you? Remove it. You don't need it.
  2.  
  3. // What type of function is this? void, int, double? Define it
  4. ProductSales::ProductSales( string name )
  5. {
  6. setProductName( name );
  7. aCount = 0;
  8. bCount = 0;
  9. cCount = 0;
  10. dCount = 0;
  11. eCount = 0;
  12. }
  13.  
  14. //// What do these statements mean?
  15. //// INT is not a valid statement all by itself.
  16. //// Neither is "( A == $2.98 )"
  17. int; ( A == $2.98 );
  18. int; ( B == $4.50 );
  19. int; ( C == $9.98 );
  20. int; ( D == $4.49 );
  21. int ( E == $6.87 );
  22.  
  23.  
  24. //// What function is this execuatable code in?
  25. do
  26. {
  27. cout << "What product sold A-E" << endl;
  28. cout << "How many sold of each" << endl;
  29. while ( product != -1 ) //end of file char
  30. {
  31. ...
  32. }
  33. }
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:



Other Threads in the C++ Forum


Views: 1427 | Replies: 7
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC