Creating a POS Receipt

Hello everyone! I would like some help on a program I'm currently writing. I need to display a receipt that shows 4 items with their quantity, unit price, and total as well as the sub-total, tax and final total. This is what I have so far.

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
 #include <iostream>
#include <ctime>
#include <string>
using namespace std;
int main()
{
	
	cout << "Colin's Capital Ventures" << endl;
	cout << "25 W Hill Drive," << endl;
	cout << "West Hartford, CT, 06119" << endl;
	cout << "(203) 860-2478" << endl;
	
	cout << "-------------------------------------------------" << endl;
	
	time_t now = time(0);
	char * dt = ctime(&now);
	cout << "Date and Time:\n" << dt << endl;
	
	tm *gmtm = gmtime(&now);
	dt = asctime(gmtm);
	
	cout << "CASHIER: Colin" << endl;
	
	cout << "\nItem";
	cout << "\t\t\t\t QTY Unit Price\tTotal" << endl;
	
	cout << "================================================================" << endl;
	
	int		quantity;
	float price, total;
	
	cout << "\nEnter the price of Item";
	
	cin >> price;
	cout << "\nEnter the item's quantity" ;
	cin >> quantity;
	
	total = quantity * price;
	
	return 0;
}
  
So what you need to do now is think how you will handle 4 items as far as getting the data in, how to store it and then how to process it.

That might mean a for 1 to 4 loop, some cin's, at least one array ( a <vector> and structs are probably out of the question ?? ), a variable(s) for subtotals and grand total, and a print heading (you've already got that bit), followed by printing the details.

Perhaps if you try it on paper first, then write some pseudo-code, and then write some real code. Otherwise we'd just be doing it for you and so far you're doing OK with printing out a receipt.


Hello colinseven,

When I tested your program it printed the beginning of the receipt then asked for input.

So, essentially you start the receipt then ask for input before you would finish the receipt. It would not look very good on the screen.

Lines 8 - 13 should be done near the end of the program after all your input.

Your input is for quantity and price, but not for an item name or description of the item. For this part you need to decide on how you will store the information before you get to printing the receipt.

Andy
Hello colinseven,

Another aspect you might consider is using functions if you're up to that in your studies. You could have a function to print the heading info, which means you can a? work on it separately and b) print the heading at whatever stage you like.

Also you could use all the same heading info and store it as a single string called str_heading or whatever. Then to print it you just
cout << str_heading << endl;
Well worth experimenting with.

againtry
Hello colinseven,

This is only set up for 1 input, but it should give you an idea:

Enter item description: Bread
Enter the price of Item: 1.95
Enter the item's quantity: 3


Colin's Capital Ventures
25 W Hill Drive,
West Hartford, CT, 06119
(203) 860-2478
-------------------------------------------------
Tue Nov 24 02:35:15 2020

CASHIER: Colin

  Item              QTY  Unit Price    Total
-------------------------------------------------
Bread                 3       1.95       5.85
Bread               300       1.95     585.00
=================================================
SubTotal                                 5.85
Tax                                      5.85
Total                                    5.85


 Press Enter to continue:


The second item line is an example of how larger number display. The tax ang total lines are for examples. Not yet dealt with.

Andy

Topic archived. No new replies allowed.