Creating a receipt - problem

Hi,

New to the forum, but seen a lot of posts so thought I'd get myself involved and see if I can seek help.


I have a system in place currently which is working well, however I want to display a receipt at the end of the transaction. I have the code to show how much the item will cost, however at the end I'd like a receipt showing the day/time as well as the cost of it and what they purchased - if also possible to print (not sure the correct words.)

New to coding, looked around but can't seem to get much information. Any help/guidance would be massively appreciated - apologies to the very bland explanation.

Since you haven't provided any code, it's hard to make specific suggestions.

Displaying the date and time:
http://www.cplusplus.com/reference/ctime/ctime/

Displaying the (total) cost is simply a matter of summing the cost of individual items purchased.

Displaying what they purchases involved keeping an array or vector of the individual items purchased, then printing out the array or vector.

Apologies for the lack of code. I've managed to get it to display the time, which works brilliantly. I'm having a bigger problem showing how much the total cost is, it's either purchasing one item or the other but it won't let me take it from the litres dispensed. Shall I message you the code?

Not wanting to make it too public because it's part of a project I'm doing.
closed account (48bpfSEw)
The first approach with my fresh successfull installed cling++ on windows **yepee yepee yeah** ^^

The code is not finished but it compiles and puts out the sum of a customer who boughts two items:

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>

class Item {
public:
  int         iID;
  std::string strName;
  float       flPrice;
};

class Customer {
public:
  int         iID;
  std::string strName;
  // std::string strAddress;
  // std::string strTelefon;
};

class Customer_bought_Item {    // Relation
public:
  int         iID_Customer;
  int         iID_Item;
  int         iNumber;
  float       flPrice_Single;
  float       flPrice_Total;
};

int main()
{
  Customer cust1;
  cust1.iID = 1000;
  cust1.strName = "Antonio Mustermann";
  
  
  Item item1;
  item1.iID = 1;
  item1.strName = "C++ Book";
  item1.flPrice = 30.0;  // euro
  
  Item item2;
  item2.iID = 2;
  item2.strName = "Computer";
  item2.flPrice = 1200.0;  // euro

  
  Customer_bought_Item cbi1;
  cbi1.iID_Customer    = cust1.iID;
  cbi1.iID_Item        = item1.iID;
  cbi1.iNumber         = 3;            // insert value
  cbi1.flPrice_Single  = item1.flPrice;
  cbi1.flPrice_Total   = cbi1.flPrice_Single * cbi1.iNumber;
  
  Customer_bought_Item cbi2;
  cbi2.iID_Customer    = cust1.iID;
  cbi2.iID_Item        = item2.iID;
  cbi2.iNumber         = 1;            // insert value
  cbi2.flPrice_Single  = item2.flPrice;
  cbi2.flPrice_Total   = cbi2.flPrice_Single * cbi2.iNumber;
  
  
  float flSum = 0.0;
  
  std::cout 
    << cbi1.iID_Customer    << " " 
    << cbi1.iID_Item        << " " 
    << cbi1.iNumber         << " " 
    << cbi1.flPrice_Single  << " " 
    << cbi1.flPrice_Total   << " " 
    << std::endl; 
    
  flSum += cbi1.flPrice_Total; 
 

  std::cout 
    << cbi2.iID_Customer    << " " 
    << cbi2.iID_Item        << " " 
    << cbi2.iNumber         << " " 
    << cbi2.flPrice_Single  << " " 
    << cbi2.flPrice_Total   << " " 
    << std::endl; 
    
  flSum += cbi2.flPrice_Total; 
 

  std::cout 
    << "Total: " << flSum << " " 
    // todo: << "Date: " << DateStr(now()) 
    << std::endl;

  return 0;
}



output:

1000 1 3 30 90
1000 2 1 1200 1200
Total: 1290
That's excellent. Very short and simple, only issue is there's only two items and you can only have one or the other. My fault for not explaining myself clearly, was just panicking and in a bit of a rush to get this complete.

How would I implement that system with this code then?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
if (option)
			cout << "Select which fuel" << endl;
		cout << " 1 = Unleaded ( 119.9 per litre )" << endl;
		cout << " 2 = Diesel ( 124.9 per litre )" << endl;
		cout << "\n" << endl;

		cin >> oilType;

		switch (oilType)
		{
		case 1:
		{
			obj.unleaded();
			break;
		}

		case 2:
		{
			obj.diesel();
			break;
		}
		};



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
	cout << "PAYMENT COMPLETE" << endl;

				cout << "\n" << endl;
				
				time_t currTime;
				struct tm timeLocal;
				time(&currTime);
				localtime_s(&timeLocal, &currTime);

				cout << " Date \n Day " << timeLocal.tm_mday <<
					"\n Month:" << timeLocal.tm_mon + 1 <<
					"\n Year: " << timeLocal.tm_year + 1900 << endl;
				cout << "Fuel Type: " << oilType << endl;
				cout <<"Liters Dispensed : " << Pump.get_liters_dispensed() << endl;
				cout << "Total Amount  : " << cost() << endl;


				}


Hope that helps anyone who can give me some guidance on where to look to get this working.
Topic archived. No new replies allowed.