Shopping Cart...

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.. need help with the loop and the finishing part of the receipt

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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>
#include <string>
#include <cctype>  // <--- For std::toupper() and tolower().
#include <math.h>

using namespace std;

int main()
{
	constexpr double TOMATOS = 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{}, G{}, L{}; 
	//int a{}, b{}, o{}, p{};
	double qty{};
	double subTotal{};
	double total{};

	std::string name; 
	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. [O]ranges $1 each " << std::endl;
	std::cout << " 2. [B]ananas $0.40 each " << std::endl;
	std::cout << " 3. [T]omatos $3 each " << std::endl;
	std::cout << " 3. [G]rapes $2.50 each " << std::endl;
	std::cout << " 4. [P]ears $1.50 each " << std::endl;
	std::cout << " 3. [L]Lemons $0.50 each " << std::endl;
	std::cout << " 5. [X]Check out " << std::endl;
	std::cin >> choice;

	if (std::toupper(choice) == 'O')
 {
	 std::cout << " How many would you like to buy? " << std::endl;
	 std::cin >> qty;
	 subTotal += ORANGES * qty;
	}
 else if (std::toupper(choice) == 'B')
 {
   std::cout << "How many would you like to buy? " <<std::endl;
   std::cin >> qty;
   subTotal += BANANAS * qty;
  }
  else if (std::toupper(choice) == 'T')
 {
   std::cout << " How many would you like to buy? " <<std::endl;
   std::cin >> qty;
   subTotal += TOMATOS * qty;
  }
  else if (std::toupper(choice) == 'G')
  {
   std::cout << " How many would you like to buy? " <<std::endl;
   std::cin >> qty;
   subTotal += GRAPES * qty;
  }
    else if (std::toupper(choice) == 'P')
  {
   std::cout << " How many would you like to buy? " <<std::endl;
   std::cin >> qty;
   subTotal += PEARS * qty;
  }
  else if (std::toupper(choice) == 'L')
  {
   std::cout << " How many would you like to buy? " <<std::endl;
   std::cin >> qty;
   subTotal += LEMONS * qty;
  }
    else if (std::toupper(choice) == 'X')
  {
   std::cout << " Your Total is..." <<std::endl;
  total = 
  }

}
Hello garza07,

Duplicate http://www.cplusplus.com/forum/beginner/236072/

Help please this is as far as I've gone.. need help with the loop and the finishing part of the receipt

Be honest this is based on what I showed you with some additions and changes on your part.

What you have left to do is figure the tax and the total before you print it out. The following is what I did with the output:

                                        GROCERY WHOLESALE

 SOLD TO:
   John Doe
   123 Main St.
   ANYWHERE  OH   43202

   Item      Qty     Price     Extension
 Apples     10.00    1.00        10.00
 Bananas    10.00    0.40         4.00
 Grapes     10.00    2.50        25.00
 Lemons     10.00    0.50         5.00
 Oranges    10.00    1.00        10.00
 Pears      10.00    1.50        15.00

 Sub Total                     $ 69.00
 Tax                           $  5.69
 Total                         $ 74.69


 Press Enter to continue

It is not easy to tell, but the first line should be centered on the screen.

Another thing you will have to consider is that the program will only work once. You will need a loop to allow more than one choice and either store the information needed or print some of the output before the loop and in the loop print for each choice made with the sub total, tax and total last.

The output you can change any way you like.

Hope that helps,

Andy
Topic archived. No new replies allowed.