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. :sad:

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

Recommended Answers

All 7 Replies

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

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.

#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.

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:

A== $2.98;
B== $4.50;
C== $9.98;
D== $4.49;
E== $6.87;

Stand for ?


Also this stmt is incorrect

cin >> C retail; >> endl;

Try to compile your code and see the plethora of errors it gives.

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.

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.

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.

#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.

#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 :sad:

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.

#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
    {
        ...
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.