..........

..........
Last edited on
Hello garza07,

Before I load the program and test it some of the things I see right off:

Lines 6 - 9 you have defined your variables as type "cahr". This type is only one byte of storage space and will hold only one character. Since these variables will be using floating point numbers type "double" is the best choice for these variables.

For now lines 9 and 10 look to be OK.

Line 12. First it is better to use lower case letters for variable names and second it is best not to use a single letter. You should give a variable a name that reflects or describes what it is or is being used for.

Line 14. You are duplicating some of the variables in line 12. Although they are lower case letters one missed shift key and you have a hard problem to find.

For both lines it is ALWAYS a good idea to initialize your variables when they are defined.

On line 26 I would add to choose by letter or remove the numbers as it could be confusing to a user.

Once I load the program and test it I will likely have more.

Hope that helps,

Andy
Hello garza07,

As I worked with the program this is what I came up with:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <string>
#include <cctype>  // <--- For std::toupper() and tolower().

//using namespace std;

int main()
{
	constexpr double APPLES = 1.0;
	constexpr double BANANAS = 0.40;
	constexpr double ORANGES = 3.0;
	constexpr double PEARS = 0.25;
	constexpr double GRAPES{ 2.5 };
	constexpr double LEMONS{ 0.5 };

	char checkout;
	char choice;
	int A{}, B{}, O{}, P{}, X{};  // <--- Needed initialized and never used.
	int a{}, b{}, o{}, p{};  // <--- Can be replaced with "qty".
	double qty{};
	double subTotal{};
	double total{};

	std::string name;  // <--- The string is empty and does not need initialized.
	std::string phone;
	std::string address;

	std::cout << "Please enter Name: ";
	std::cin >> name;
	std::cout << "Phone Number: ";
	std::cin >> phone;
	std::cout << "Address: ";
	std::cin >> address;

	//Check in
	// Missing grapes and lemons and exit.
	std::cout << " What would you like to Purchase " << std::endl;
	std::cout << " 1. [A]pples 1/lb " << std::endl;
	std::cout << " 2. [B]ananas 0.4/lb " << std::endl;
	std::cout << " 3. [O]ranges 3/lb " << std::endl;
	std::cout << " 4. [P]ears 2.5/lb " << std::endl;
	std::cin >> choice;

	if (std::toupper(choice) == 'A')
	{
		std::cout << " How many LBS would you like to buy? " << std::endl;
		std::cin >> qty;
		subTotal += APPLES * qty;
	}

This is the beginning and will give you an idea how to change what follows.

What I would do is put most of the program in a do/while or while loop, so that you can continue ordering until you choose to exit. I would also use a switch in place of the if/else if statements.

I added the variable "subTotal" and as you can see in the if block for 'A' it says "+=" otherwise every time you order something it would over wright what you did previous.

Some things you will see different from what you did:

At the beginning of main I have the section that begins with "constexpr" or you could just use "const", the former is the newer version. Since they deal with floating point numbers I made them doubles and the capital letters let you know that it is a constant that can not be changed. Normally I would put these lines above main so they are easy to find when any changes are needed.

The regular variables start with a lower case letter and the rest is lower case letters unless you put to words together then it is called camel case as in "subTotal".

Before you work on the checkout part you need to get the first part working first.

Hope that helps,

Andy
..........
Last edited on
garza07, I think you accidentally deleted your post. Please do not delete your posts after your problem has been resolved, it doesn't make the forum cleaner. This forum can exist to help others that might run into similar problems as you. Have a good one...

Original Post:
garza07 wrote:

You are going to create a shopping cart using C++ program.
First, the program will ask user’s information (name, address, phone number). Then, display the
items menu:
1. Orange $1.00 each
2. Banana $0.40 each
3. Tomato $3.00 each
4. Grape $2.50 each
5. Pear $1.50 each
6. Lemon $0.50 each
The program will let the user purchase different item with different quantities each time using
loops (you can use any loop). Then, the program calculates the sub-total of each item (subtotal
before tax, tax, and sub-total after tax), assume tax is 8.25%.
At the end, print a receipt include user’s information, purchase items and sub-totals, and finally,
the total price before tax, total tax, and total price after tax.


Help please this is as far as i've gone

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <string>
using namespace std;
int main ()
{
    char Apples = 1;
    char Bananas = 0.40;
    char Oranges = 3;
    char Pears = 0.25;
    char checkout;
    char choice;
    int total, A, B, O, P, X ;

    int a, b, o, p, n, ph, ad;


    cout << "Please enter Name: ";
    cin>> n;
    cout << "Phone Number: ";
    cin>> ph;
    cout << "Address: ";
    cin>> ad;
 
    //Check in

    cout << " What would you like to Purchase " << endl;
    cout << " 1. [A]pples 1/lb " << endl;
    cout << " 2. [B]ananas 0.4/lb " << endl;
    cout << " 3. [O]ranges 3/lb " << endl;
    cout << " 4. [P]ears 2.5/lb " << endl;
    cin>>choice;

    if ( choice=='A')
    {
        cout << " How many LBS would you like to buy? " << endl;
        cin >> a;
        total= Apples*a;
    }
    else if (choice =='B')
    {
        cout << " How many LBS would you like to buy? " << endl;
        cin>>b;
        total = Bananas*b;

    }
    else if (choice == 'O')
    {
        cout << " How many LBS would you like to buy? " << endl;
        cin>>o;
        total = Oranges*o;
    }
    else if (choice=='P')
    {
        cout << " How many LBS would you like to buy? " << endl;
        cin>>p;
        total = Pears*p;

    }
    else if (choice=='X')
    {
        cout << " Would you like to check out? " << endl;
        cin>>checkout;
        total= A+B+O+P;
    }


}
Last edited on
Topic archived. No new replies allowed.