| | |
Help please
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2006
Posts: 4
Reputation:
Solved Threads: 0
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
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
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
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
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
•
•
Join Date: Oct 2006
Posts: 4
Reputation:
Solved Threads: 0
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.
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.
C++ Syntax (Toggle Plain Text)
#include "stdafx.h" #include <iostream> using std::cout; using std::cin; using std::endl; #include "Ch5.h" cout << "Product A value $2.98" << endl; cout << "Product B value $4.50" << endl; cout << "Product C value $9.98" << endl; cout << "Product D value $4.49" << endl; cout << "Product E value $6.87" << endl; cout << " " << endl; A== $2.98; B== $4.50; C== $9.98; D== $4.49; E== $6.87; do { cout << "Enter total sold of product A"; cin >> Atotal; cout << "Enter total sold of product B"; cin >> Btotal; cout << "Enter total sold of product C"; cin << Ctotal; cout << "Enter total sold of product D"; cin >> Dtotal; cout << "Enter total sold of product E"; cin >> Etotal; cout << "Enter 1 to quit"; cin >> 1 >> endl; switch (actual retail price) { case 'A': case 'a': cout << "Product A retail value" <<endl; cin >> A retail; >>endl; break; case 'B': case 'b': cout << "Product B retail value" << endl; cin >> B retail; >> endl; break; case 'C': case 'c': cout << "Product C retail value" << endl; cin >> C retail; >> endl; break; case 'D': case 'd': cout << "Product D retail value" << endl; cin >> D retail; >> endl; break; case 'E': case 'e': cout << "Product E retail value" << endl; cin >> E retail; >> endl; case '1': cout << "Good bye" << endl; break; }
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
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:
Stand for ?
Also this stmt is incorrect
Try to compile your code and see the plethora of errors it gives.
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:
C++ Syntax (Toggle Plain Text)
A== $2.98; B== $4.50; C== $9.98; D== $4.49; E== $6.87;
Also this stmt is incorrect
C++ Syntax (Toggle Plain Text)
cin >> C retail; >> endl;
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
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
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.
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
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
•
•
Join Date: Oct 2006
Posts: 4
Reputation:
Solved Threads: 0
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.
Here is the header file.
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
C++ Syntax (Toggle Plain Text)
#include "stdafx.h" #include <iostream> using std::cout; using std::cin; using std::endl; #include "Ch5.12.h" // // ProductSales::ProductSales( string name ) { setProductName( name ); aCount = 0; bCount = 0; cCount = 0; dCount = 0; eCount = 0; } void ProductSales::inputSales { int sales; cout << "Enter each products total sales. " << endl << "Enter -1 to end input." << endl; } int; ( A == $2.98 ); int; ( B == $4.50 ); int; ( C == $9.98 ); int; ( D == $4.49 ); int ( E == $6.87 ); do { cout << "What product sold A-E" << endl; cout << "How many sold of each" << endl; while ( product != -1 ) //end of file char { switch (product) { case 'A': case 'a': cout << "A total sales" <<endl; cin >> A sales; >>endl; break; case 'B': case 'b': cout << "B total sales" << endl; cin >> B sales; >> endl; break; case 'C': case 'c': cout << "C total sales" << endl; cin >> C sales; >> endl; break; case 'D': case 'd': cout << "D total sales" << endl; cin >> D sales; >> endl; break; case 'E': case 'e': cout << "E total sales" << endl; cin >> E sales; >> endl; case '-1': cout << "Good bye" << endl; break; } } } void ProductSales::displayProductSales { cout << "\nA: " << aCount // displays Product A sales << "\nB: " << bCount // displays Product B sales << "\nC: " << cCount // displays Product C sales << "\nD: " << dCount // displays Product D sales << "\nE: " << eCount // displays Product E sales << endl; // ends the function display Product sales }
Here is the header file.
C++ Syntax (Toggle Plain Text)
#include <string> using std::string; class ProductSales { public: ProductSales( string ); void setProductName(); void inputSales(); void displayProductSales private: string productName int aCount; int bCount; int cCount; int dCount; int eCount; };
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.
•
•
•
•
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.
C++ Syntax (Toggle Plain Text)
#include "stdafx.h" //// What's this statement do for you? Remove it. You don't need it. // What type of function is this? void, int, double? Define it ProductSales::ProductSales( string name ) { setProductName( name ); aCount = 0; bCount = 0; cCount = 0; dCount = 0; eCount = 0; } //// What do these statements mean? //// INT is not a valid statement all by itself. //// Neither is "( A == $2.98 )" int; ( A == $2.98 ); int; ( B == $4.50 ); int; ( C == $9.98 ); int; ( D == $4.49 ); int ( E == $6.87 ); //// What function is this execuatable code in? do { cout << "What product sold A-E" << endl; cout << "How many sold of each" << endl; while ( product != -1 ) //end of file char { ... } }
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
![]() |
Other Threads in the C++ Forum
- Previous Thread: txt data into 2d Array
- Next Thread: Nested << operator
Views: 1427 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






