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 :)
#include <iostream>
#include <string>
usingnamespace 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();
}
elseif (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;
}
elseif(a == "2"){
cout << "You have choosen number " << a << "\n" <<endl;
total = total + 110;
cout << "Your Total for now is : " <<total << "\n" <<endl;
}
elseif(a == "3"){
cout << "You have choosen number " << a << "\n" <<endl;
total = total + 150;
cout << "Your Total for now is : " <<total << "\n" <<endl;
}
elseif(a == "4"){
cout << "You have choosen number " << a << "\n" <<endl;
total = total + 190;
cout << "Your Total for now is : " <<total << "\n" <<endl;
}
elseif(a == "5"){
cout << "You have choosen number " << a << "\n" <<endl;
total = total + 130;
cout << "Your Total for now is : " <<total << "\n" <<endl;
}
elseif(a == "6"){
cout << "You have choosen number " << a << "\n" <<endl;
total = total + 170;
cout << "Your Total for now is : " <<total << "\n" <<endl;
}
elseif(a == "7"){
cout << "You have choosen number " << a << "\n" <<endl;
total = total + 210;
cout << "Your Total for now is : " <<total << "\n" <<endl;
}
elseif(a == "H"||a == "h"){
hair();
}
elseif(a =="#"){
a = "#";
}
elseif(a =="*"){
a = "*";
}
else{
cout << "Please Check Your Code!\n"<<endl;
}
}while(a!= "#" && a!= "*");
if (a =="#"){
cout << "Total Price = "<<total<<endl;
getchar();
}
elseif(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;
}
elseif(a == "2"){
cout << "You have choosen number " << a << "\n" <<endl;
total = total + 28;
cout << "Your Total for now is : " <<total << "\n" <<endl;
}
elseif(a == "3"){
cout << "You have choosen number " << a << "\n" <<endl;
total = total + 20;
cout << "Your Total for now is : " <<total << "\n" <<endl;
}
elseif(a == "4"){
cout << "You have choosen number " << a << "\n" <<endl;
total = total + 110;
cout << "Your Total for now is : " <<total << "\n" <<endl;
}
elseif(a == "5"){
cout << "You have choosen number " << a << "\n" <<endl;
total = total + 95;
cout << "Your Total for now is : " <<total << "\n" <<endl;
}
elseif(a == "6"){
cout << "You have choosen number " << a << "\n" <<endl;
total = total + 220;
cout << "Your Total for now is : " <<total << "\n" <<endl;
}
elseif(a == "7"){
cout << "You have choosen number " << a << "\n" <<endl;
total = total + 180;
cout << "Your Total for now is : " <<total << "\n" <<endl;
}
elseif(a == "B"||a == "b"){
body();
}
elseif(a =="#"){
a = "#";
}
elseif(a =="*"){
a = "*";
}
else{
cout << "Please Check Your Code!\n"<<endl;
}
}while(a!= "#" && a!= "*");
if (a =="#"){
cout << "Total Price = "<<total <<endl;
getchar();
}
elseif(a == "*"){
total = (total * 0.75);
cout << "Total Price = "<<total<<endl;
getchar();
}
}
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.
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.
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.
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 :)