anyone could solve this ? :(

I have done a code for my college assignment. I want the user to have 2 choices bill in "body treatment" or "hair treatment". For an example, the user has choose "body treatment" and he has choose the treatment and he wants to choose on "hair treatment". The program i created is just applicable for one treatment only. Is it possible to modify the code to have 2 choices and check out the total price. Thanks for anyone who could help me :)

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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <iostream>
#include <string>
using namespace std;
void body();
void hair();
double total = 0;
int main(){
string require;
system("Color 1A");
cout << "-----------------------------" << endl;
cout << "|WELCOME TO LUCKY BEAUTY SPA|" <<endl;
cout << "-----------------------------" << endl;
cout << "Guideline : \n1 Type B for Body Treatment and type H for Hair treatment\n2 To check out type #\n3 For member 25% discount type *" <<endl;
cout << "--------------------------------------------------------------------------------" <<endl;
cout << "Body Treatment = B\n1 Herbal Bath\tRM200\n2 Tradition Massage (60m)\tRM110\n3 Tradition Massage (90m)\tRM150\n4 Tradition Massage (120m)\tRM190\n5 Tradition Aromatherapy Massage (60m)\tRM130\n6 Tradition Aromatherapy Massage (90m)\tRM170\n7 Tradition Aromatherapy Massage (120m)\tRM210\n\nHair Treatment = H\n1 Hair Cut\tRM35\n2 Shampoo & Blow (Long)\tRM28\n3 Shampoo & Blow (Short)\tRM20\n4 Coloring (Long)\tRM110\n5 Coloring (Short)\tRM95\n6 Hair Treatment (Long)\tRM220\n7 Hair Spa (Short)\tRM180\n"<<endl;
cout << "--------------------------------------------------------------------------------" <<endl;
cout << "Please Choose Body Treatment or Hair Treatment\n" <<endl;
cin >> require;
if (require == "h" || require == "H"){
hair();
}
else if (require == "B" || require == "b"){
body();
}
else{
cout << "Please Check Your Code!\n"<<endl;
}
getchar();
return main();
}
void body(){
string a;
do{
cout << "Choose for body treatment\n"<<endl;
cin >> a;
if(a == "1"){
cout << "You have choosen number " << a << "\n" <<endl;
total = total + 200;
cout << "Your Total for now is : " <<total << "\n" <<endl;
}
else if(a == "2"){
cout << "You have choosen number " << a << "\n" <<endl;
total = total + 110;
cout << "Your Total for now is : " <<total << "\n" <<endl;
}
else if(a == "3"){
cout << "You have choosen number " << a << "\n" <<endl;
total = total + 150;
cout << "Your Total for now is : " <<total << "\n" <<endl;
}
else if(a == "4"){
cout << "You have choosen number " << a << "\n" <<endl;
total = total + 190;
cout << "Your Total for now is : " <<total << "\n" <<endl;
}
else if(a == "5"){
cout << "You have choosen number " << a << "\n" <<endl;
total = total + 130;
cout << "Your Total for now is : " <<total << "\n" <<endl;
}
else if(a == "6"){
cout << "You have choosen number " << a << "\n" <<endl;
total = total + 170;
cout << "Your Total for now is : " <<total << "\n" <<endl;
}
else if(a == "7"){
cout << "You have choosen number " << a << "\n" <<endl;
total = total + 210;
cout << "Your Total for now is : " <<total << "\n" <<endl;
}
else if(a == "H"||a == "h"){
hair();
}
else if(a =="#"){
a = "#";
}
else if(a =="*"){
a = "*";
}
else{
cout << "Please Check Your Code!\n"<<endl;
}
}while(a!= "#" && a!= "*");
if (a =="#"){
cout << "Total Price = "<<total<<endl;
getchar();
}
else if(a == "*"){
total = (total * 0.75);
cout << "Total Price = "<<total<<endl;
getchar();
}
}
void hair(){
string a;
do{
cout << "Choose for Hair treatment\n"<<endl;
cin >> a;
if(a == "1"){
cout << "You have choosen number " << a << "\n" <<endl;
total = total + 35;
cout << "Your Total for now is : " <<total << "\n" <<endl;
}
else if(a == "2"){
cout << "You have choosen number " << a << "\n" <<endl;
total = total + 28;
cout << "Your Total for now is : " <<total << "\n" <<endl;
}
else if(a == "3"){
cout << "You have choosen number " << a << "\n" <<endl;
total = total + 20;
cout << "Your Total for now is : " <<total << "\n" <<endl;
}
else if(a == "4"){
cout << "You have choosen number " << a << "\n" <<endl;
total = total + 110;
cout << "Your Total for now is : " <<total << "\n" <<endl;
}
else if(a == "5"){
cout << "You have choosen number " << a << "\n" <<endl;
total = total + 95;
cout << "Your Total for now is : " <<total << "\n" <<endl;
}
else if(a == "6"){
cout << "You have choosen number " << a << "\n" <<endl;
total = total + 220;
cout << "Your Total for now is : " <<total << "\n" <<endl;
}
else if(a == "7"){
cout << "You have choosen number " << a << "\n" <<endl;
total = total + 180;
cout << "Your Total for now is : " <<total << "\n" <<endl;
}
else if(a == "B"||a == "b"){
body();
}
else if(a =="#"){
a = "#";
}
else if(a =="*"){
a = "*";
}
else{
cout << "Please Check Your Code!\n"<<endl;
}
}while(a!= "#" && a!= "*");
if (a =="#"){
cout << "Total Price = "<<total <<endl;
getchar();
}
else if(a == "*"){
total = (total * 0.75);
cout << "Total Price = "<<total<<endl;
getchar();
}
}
have you compiled it? any error messages?
There is no error in this program, what i want is user could choose two different "treatment". This program only could choose one "treatment" at once.
you want a loop that continually asks the user for choices (until they press 'q' for quit for example).
store those choices in a vector or something like that.
then we you come to add up the price loop through vector and sum all the costs.
Can I just say that this code is DIEING for a switch statement instead of all the if's and else's
Yep. You can even say "dying" as well.
But it's better to get working code before even worrying about tidying it up.
Last edited on
Please don't use this return main();

First it's not legal code, you cannot call main()

Secondly, if it was permitted, it would be a poor design. Use a while loop or some other kind of loop instead.
Last edited on
Yea, i want it to be something like the user could do 2 transaction in one time. for now the program only could do for one transaction. For an example if the user choose hair treatment they only could choose the options for that, they couldn't go back and choose the body treatment.
& the code is just working well, you guys could test it :)
Please don't use this return main();


god, i didnt even see this.

can i know why cannot use the return main ?
The problem is that this is illegal in ISO C++.

Some compilers may permit it, however if for some reason you need to use a different compiler, then it may simply output an error message and halt the compilation.

can i know why cannot use the return main ?


Can you tell us why you think you should be returning this?
Yep. You can even say "dying" as well.
But it's better to get working code before even worrying about tidying it up.

Yep you could say "dying" XD
But also a tidier code makes it much easier to search for errors.
He'd have to do more than just change to a switch statement currently, though. He's comparing strings and you can't switch that. However in this case it wouldn't be too bad as he's effectively comparing chars.
I did notice that, it's the characters used in all the if's and else's, and hopefully we should all know that a char is just an integer so a switch statement should be perfectly fine :)
Topic archived. No new replies allowed.