Point of Sales (Need help)

Hi guys! I'm making a program for point of sales. Will you please help me? I want my program to display another transaction when the user type T. If the user input yes, the program will display another transaction. If no, the program will terminate. Any help/suggestions will be appreciated.

PS: Sorry for bad grammar.

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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <iostream>

using namespace std;

double apples;
double pears;
double watermelons;
double oranges;
double appleshake;
double pearshake;
double watermelonshake;
double orangeshake;
double total = 0;
float userchoice; 
int T;
int T_answer;

int main()
{
    while (total >= 0)
    {
        cout << "\n\n Welcome to Fruity Patootie!!\n\n";
        cout << "Menu:\n\n";
        cout << "Fruits:\n";
        cout << "------------------------------------\n";
        cout << "1     Apples                 P10.00\n";
        cout << "2     Pears                  P10.00\n";
        cout << "3     Watermelons            P20.00\n";
        cout << "4     Oranges                P10.00\n\n";
        cout << "Shakes:\n";
        cout << "------------------------------------\n";
        cout << "5     Apple Shake            P15.00\n";
        cout << "6     Pear Shake             P17.00\n";
        cout << "7     Watermelon Shake       P25.00\n";
        cout << "8     Orange Shake           P12.00\n\n";
        cout << "\nYou have:\n" << apples << " Apples\n" << pears << " Pears\n" << watermelons << " Watermelons\n" << oranges << " Oranges\n" << appleshake << " Apple Shake\n" << pearshake << " Pear Shake\n" << watermelonshake <<" Watermelon Shake\n" << orangeshake << " Orange Shake\n";
        cout << "Total amount:                P" << total << ".00\n\n";
        cout << "Type the number that represents the fruit you want or type T to check out.\n";
        cin >> userchoice;
        
        if (userchoice == 1)
        {
            apples++;
            total = total += 10.00;
        }
        
        if (userchoice == 2)
            total = total += 10.00;
        }
        
        if (userchoice == 3)
        {
            watermelons++;
            total = total += 20.00;
        }
        
        if (userchoice == 4)
        {
            oranges++;
            total = total += 10.00;
        }
        
        if (userchoice == 5)
        {
            appleshake++;
            total = total += 15.00;
        }
        
        if (userchoice == 6)
        {
            pearshake++;
            total = total += 17.00;
        }
        
        if (userchoice == 7)
        {
            watermelonshake++;
            total = total += 25.00;
        }
        
        if (userchoice == 8)
        {
            orangeshake++;
            total = total += 12.00;
        }
        
		if (userchoice == T)
        {
            cout << "\n\n Thank you for shopping\n\n";
            cout << "Do you want another transaction? Y/N\n";
            cin >> T_answer; 
        if (T_answer == 'Y')
            {
            cout << "\n\n Welcome to Fruity Patootie!!\n\n";
            cout << "Menu:\n\n";
            cout << "Fruits:\n";
            cout << "------------------------------------\n";
            cout << "1     Apples                 P10.00\n";
            cout << "2     Pears                  P10.00\n";
            cout << "3     Watermelons            P20.00\n";
            cout << "4     Oranges                P10.00\n\n";
            cout << "Shakes:\n";
            cout << "------------------------------------\n";
            cout << "5     Apple Shake            P15.00\n";
            cout << "6     Pear Shake             P17.00\n";
            cout << "7     Watermelon Shake       P25.00\n";
            cout << "8     Orange Shake           P12.00\n\n";
            cout << "\nYou have:\n" << apples << " Apples\n" << pears << " Pears\n" << watermelons << " Watermelons\n" << oranges << " Oranges\n" << appleshake << " Apple Shake\n" << pearshake << " Pear Shake\n" << watermelonshake <<" Watermelon Shake\n" << orangeshake << " Orange Shake\n";
            cout << "Total amount:                P" << total << ".00\n\n";
            cout << "Type the number that represents the fruit you want or type T to check out.\n";
            cin >> userchoice;
			}
	    if (T_answer == 'N')
	        {
	    	cout << "Thank you for shopping!";
	    	return 0;
		   }
        }
        
   

return 0;
}
Firstly, you can't store letters in an int or a float. You should use char for userchoice, and T_answer. I also don't see where int T is used in your code.

Next, you have total = total += 10.00; in each of your if statements. That's a bit redundant. Total += will add the value and then set it. so using total = total + 10.00; and total += 10.00; are functionally the same.

Also, you're missing an opening bracket
1
2
3
4
 
if (userchoice == 2)
total = total += 10.00;
}


Finally, I would change the last few lines of your code. Set your while loop to
while(T_answer != 'N' && T_answer != 'n')
This way your while loop will continue to run until the user chooses N on the final question. That will allow you to clean the end of your code a bit like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
        if (userchoice == '8')
        {
            orangeshake++;
            total += 12.00;
        }
        
		if (userchoice == 'T' || userchoice == 't')
        {
            cout << "\n\n Thank you for shopping\n\n";
            cout << "Do you want another transaction? Y/N\n";
            cin >> T_answer; 
        }
	    if (T_answer == 'N'  || T_answer == 'n')
	        {
	    	cout << "Thank you for shopping!";
	    	return 0;
	        }


I included the userchoice option for orangeshake to show how I would program those statements to look.

Let me know if you have any other questions.
Last edited on
I changed everything you said. The T_answer works fine but the menu can't total the amount of items. Here's the code:

#include <iostream>

using namespace std;
double apples;
double pears;
double watermelons;
double oranges;
double appleshake;
double pearshake;
double watermelonshake;
double orangeshake;
double total = 0;
char userchoice;
char T_answer;

int main()
{
while (T_answer != 'N' && T_answer != 'n')
{
cout << "\n\n Welcome to Fruity Patootie!!\n\n";
cout << "Menu:\n\n";
cout << "Fruits:\n";
cout << "------------------------------------\n";
cout << "1 Apples P10.00\n";
cout << "2 Pears P10.00\n";
cout << "3 Watermelons P20.00\n";
cout << "4 Oranges P10.00\n\n";
cout << "Shakes:\n";
cout << "------------------------------------\n";
cout << "5 Apple Shake P15.00\n";
cout << "6 Pear Shake P17.00\n";
cout << "7 Watermelon Shake P25.00\n";
cout << "8 Orange Shake P12.00\n\n";
cout << "\nYou have:\n" << apples << " Apples\n" << pears << " Pears\n" << watermelons << " Watermelons\n" << oranges << " Oranges\n" << appleshake << " Apple Shake\n" << pearshake << " Pear Shake\n" << watermelonshake <<" Watermelon Shake\n" << orangeshake << " Orange Shake\n";
cout << "Total amount: P" << total << ".00\n\n";
cout << "Type the number that represents the fruit you want or type T to check out.\n";
cin >> userchoice;

if (userchoice == 1)
{
apples++;
total = total + 10.00;
}

if (userchoice == 2)
{

total = total + 10.00;
}

if (userchoice == 3)
{
watermelons++;
total = total + 20.00;
}

if (userchoice == 4)
{
oranges++;
total = total + 10.00;
}

if (userchoice == 5)
{
appleshake++;
total = total + 15.00;
}

if (userchoice == 6)
{
pearshake++;
total = total + 17.00;
}

if (userchoice == 7)
{
watermelonshake++;
total = total + 25.00;
}

if (userchoice == 8)
{
orangeshake++;
total = total + 12.00;
}

if (userchoice == 'T' || userchoice == 't')
{
cout << "Do you want another transaction? Y/N\n";
cin >> T_answer;
}
if (T_answer == 'Y' || T_answer =='y')
{
cout << "\n\n Welcome to Fruity Patootie!!\n\n";
cout << "Menu:\n\n";
cout << "Fruits:\n";
cout << "------------------------------------\n";
cout << "1 Apples P10.00\n";
cout << "2 Pears P10.00\n";
cout << "3 Watermelons P20.00\n";
cout << "4 Oranges P10.00\n\n";
cout << "Shakes:\n";
cout << "------------------------------------\n";
cout << "5 Apple Shake P15.00\n";
cout << "6 Pear Shake P17.00\n";
cout << "7 Watermelon Shake P25.00\n";
cout << "8 Orange Shake P12.00\n\n";
cout << "\nYou have:\n" << apples << " Apples\n" << pears << " Pears\n" << watermelons << " Watermelons\n" << oranges << " Oranges\n" << appleshake << " Apple Shake\n" << pearshake << " Pear Shake\n" << watermelonshake <<" Watermelon Shake\n" << orangeshake << " Orange Shake\n";
cout << "Total amount: P" << total << ".00\n\n";
cout << "Type the number that represents the fruit you want or type T to check out.\n";
cin >> userchoice;
}
if (T_answer == 'N' || T_answer == 'n')
{
cout << "Thank you for shopping!";
return 0;
}
}




return 0;
}
When you type a reply on the very right side of the text box it says Format:
when you click it you get {code}{/code} except in brackets []. Put your code between the two and it'll post your code in an easier to read format as shown:

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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <iostream>

using namespace std;
double apples;
double pears;
double watermelons;
double oranges;
double appleshake;
double pearshake;
double watermelonshake;
double orangeshake;
double total = 0;
char userchoice; 
char T_answer;

int main()
{
while (T_answer != 'N' && T_answer != 'n')
{
cout << "\n\n Welcome to Fruity Patootie!!\n\n";
cout << "Menu:\n\n";
cout << "Fruits:\n";
cout << "------------------------------------\n";
cout << "1 Apples P10.00\n";
cout << "2 Pears P10.00\n";
cout << "3 Watermelons P20.00\n";
cout << "4 Oranges P10.00\n\n";
cout << "Shakes:\n";
cout << "------------------------------------\n";
cout << "5 Apple Shake P15.00\n";
cout << "6 Pear Shake P17.00\n";
cout << "7 Watermelon Shake P25.00\n";
cout << "8 Orange Shake P12.00\n\n";
cout << "\nYou have:\n" << apples << " Apples\n" << pears << " Pears\n" << watermelons << " Watermelons\n" << oranges << " Oranges\n" << appleshake << " Apple Shake\n" << pearshake << " Pear Shake\n" << watermelonshake <<" Watermelon Shake\n" << orangeshake << " Orange Shake\n";
cout << "Total amount: P" << total << ".00\n\n";
cout << "Type the number that represents the fruit you want or type T to check out.\n";
cin >> userchoice;

if (userchoice == 1)
{
apples++;
total = total + 10.00;
}

if (userchoice == 2)
{

total = total + 10.00;
}

if (userchoice == 3)
{
watermelons++;
total = total + 20.00;
}

if (userchoice == 4)
{
oranges++;
total = total + 10.00;
}

if (userchoice == 5)
{
appleshake++;
total = total + 15.00;
}

if (userchoice == 6)
{
pearshake++;
total = total + 17.00;
}

if (userchoice == 7)
{
watermelonshake++;
total = total + 25.00;
}

if (userchoice == 8)
{
orangeshake++;
total = total + 12.00;
}

if (userchoice == 'T' || userchoice == 't')
{
cout << "Do you want another transaction? Y/N\n";
cin >> T_answer; 
}
if (T_answer == 'Y' || T_answer =='y')
{
cout << "\n\n Welcome to Fruity Patootie!!\n\n";
cout << "Menu:\n\n";
cout << "Fruits:\n";
cout << "------------------------------------\n";
cout << "1 Apples P10.00\n";
cout << "2 Pears P10.00\n";
cout << "3 Watermelons P20.00\n";
cout << "4 Oranges P10.00\n\n";
cout << "Shakes:\n";
cout << "------------------------------------\n";
cout << "5 Apple Shake P15.00\n";
cout << "6 Pear Shake P17.00\n";
cout << "7 Watermelon Shake P25.00\n";
cout << "8 Orange Shake P12.00\n\n";
cout << "\nYou have:\n" << apples << " Apples\n" << pears << " Pears\n" << watermelons << " Watermelons\n" << oranges << " Oranges\n" << appleshake << " Apple Shake\n" << pearshake << " Pear Shake\n" << watermelonshake <<" Watermelon Shake\n" << orangeshake << " Orange Shake\n";
cout << "Total amount: P" << total << ".00\n\n";
cout << "Type the number that represents the fruit you want or type T to check out.\n";
cin >> userchoice;
}
if (T_answer == 'N' || T_answer == 'n')
{
cout << "Thank you for shopping!";
return 0;
}
}




return 0;
}
Report
Try replacing all of your total = total + //price with total += //price and see if that solves it.

Also, you shouldn't need any of the code for if the user answers y to make another transaction. If the user answers n, the code exits the loop, but if they answer y it should just loop back through.
Last edited on
Topic archived. No new replies allowed.