Как мне зациклить "Хотели бы вы купить что-нибудь еще?"он находится внизу большей части кода, после ответа «Да», затем он снова вернется к выбору из доступных категорий.
Я снова установлю переключатель после того, как узнаю, как можно зациклить этот
#include <iostream>
using namespace std;
char acoustic, electric, drums, piano, music, equip, Yes, No;
int pay1, pay2, pay3, pay4, pay5;
std::string answer;
int main()
{
cout << "Welcome to the Music Shop" << endl <<endl;
cout << "Categories Products Price"<<endl;
cout << "[a] Acoustic Guitar Fender Acoustic Guitar P6,900.00"<< endl;
cout << " Hartwood Acoustic Guitar P6,300.00" << endl;
cout << "[b] Electric Guitar Gibson Electric Guitar P8,500.00" << endl;
cout << " Ibanez Electric Guitar P25,000.00" << endl;
cout << "[c] Drums Pearl Drum Kits P27,000.00" << endl;
cout << " Roland Electronic Drums P24,000.00" << endl;
cout << "[d] Piano Casio Digital Piano P19,000.00" << endl;
cout << " Roland Piano P120,000.00" << endl;
cout << "[e] Music Equipments Guitar String P113.00" << endl;
cout << " Headphones P1,600.00" << endl;
cout << " Amplifier P2,800.00" << endl;
cout << " Digital Mixer P4,750.00" << endl;
cout << " Vocal Microphone P860.00" << endl;
cout << " Guitar Tuner P537.00" << endl;
cout << " Guitar Pick P360.00" << endl<<endl;
cout << "Choose from the available categories: ";
cin >> music;
switch (music)
{
case 'a':
cout<< "Acoustic Guitar" << endl;
cout<< "1. Fender Acoustic Guitar - P6,900.00" << endl;
cout<< "2. Hartwood Acoustic Guitar - P6,300.00" << endl <<endl;
cout<<"Choose from the available Acoustic Guitars:";
cin>>acoustic;
if (acoustic == '1'){
cout<<"Enter your payment:";
cin>>pay1;
if (pay1==6900){
cout<<"You have succesfully purchased Fender Acoustic Guitar"<<endl;
}
else if (pay1>6900){
pay1 -= 6900;
cout<<"Your change is:"<<pay1<<endl;
}
else if (pay1<6900){
cout<<"You do not have enough money"<<endl;
}
}
else if (acoustic == '2'){
cout<<"Enter your payment:";
cin>>pay1;
if (pay1==6300){
cout<<"You have succesfully purchased Fender Acoustic Guitar"<<endl;
}
else if (pay1>6300){
pay1 -= 6300;
cout<<"Your change is:"<<pay1<<endl;
}
else if (pay1<6300)
{
cout<<"You do not have enough money"<<endl;
}
}
else {
cout<<"Invalid"<<endl;
}
break;
case 'b':
cout<< "Electric Guitar" << endl;
cout<< "1. Gibson Electric Guitar -P8,500.00" << endl;
cout<< "2. Ibanez Electric Guitar -P25,000.00" << endl <<endl;
cout<<"Choose from the available Electric Guitars:";
cin>>electric;
if (electric=='1'){
cout<<"Enter your payment:";
cin>>pay2;
if (pay2==8500){
cout<<"You have succesfully purchased Fender Acoustic Guitar"<<endl;
}
else if (pay2>8500){
pay2 -= 8500;
cout<<"Your change is:"<<pay2<<endl;
}
else if(pay2<8500)
{
cout<<"You do not have enough money"<<endl;
}
}
else if (electric=='2'){
cout<<"Enter your payment:";
cin>>pay2;
if (pay2==25000)
{
cout<<"You have succesfully purchased Fender Acoustic Guitar"<<endl;
}
else if (pay2>25000){
pay2 -= 25000;
cout<<"Your change is:"<<pay2<<endl;
}
else if (pay2<25000)
{
cout<<"You do not have enough money"<<endl;
}
}
else {
cout<<"Invalid";
}
break;
case 'c':
cout<< "Drums" << endl;
cout<< "1. Pearl Drum Kits -P27,000.00" << endl;
cout<< "2. Roland Electronic Drums -P24,000.00" << endl <<endl;
cout<<"Choose from the available Drums:";
cin>>drums;
if (drums=='1'){
cout<<"Enter your payment:";
cin>>pay3;
if (pay3==27000){
cout<<"You have succesfully purchased Pearl Drum Kits"<<endl;
}
else if (pay3>27000){
pay3 -= 27000;
cout<<"Your change is:"<<pay3<<endl;
}
else if(pay3<27000)
{
cout<<"You do not have enough money"<<endl;
}
}
else if (drums=='2'){
cout<<"Enter your payment:";
cin>>pay3;
if (pay3==24000)
{
cout<<"You have succesfully purchased Rolans Electronic Drums"<<endl;
}
else if (pay3>24000){
pay3 -= 24000;
cout<<"Your change is:"<<pay3<<endl;
}
else if (pay3<25000)
{
cout<<"You do not have enough money"<<endl;
}
}
else {
cout<<"Invalid";
}
break;
case 'd':
cout<< "Piano" << endl;
cout<< "1. Casio Digital Piano -P19,000.00" << endl;
cout<< "2. Roland Piano -P120,000.00" << endl <<endl;
cout<<"Choose from the available Piano:";
cin>>piano;
if (piano=='1'){
cout<<"Enter your payment:";
cin>>pay4;
if (pay4==19000){
cout<<"You have succesfully purchased Casio Digital Piano"<<endl;
}
else if (pay4>19000){
pay4 -= 19000;
cout<<"Your change is:"<<pay4<<endl;
}
else if(pay4<19000)
{
cout<<"You do not have enough money"<<endl;
}
}
else if (piano=='2'){
cout<<"Enter your payment:";
cin>>pay4;
if (pay4==120000){
cout<<"You have succesfully purchased Roland Piano"<<endl;
}
else if (pay4>120000){
pay4 -= 120000;
cout<<"Your change is:"<<pay4<<endl;
}
else if(pay4<120000)
{
cout<<"You do not have enough money"<<endl;
}
}
else {
cout<<"Invalid";
}
break;
case 'e':
cout<< "Music Equipments" << endl;
cout << "1. Guitar String -P113.00" << endl;
cout << "2. Headphones -P1,600.00" << endl;
cout << "3. Amplifier -P2,800.00" << endl;
cout << "4. Digital Mixer -P4,750.00" << endl;
cout << "5. Vocal Microphone -P860.00" << endl;
cout << "6. Guitar Tuner -P537.00" << endl;
cout << "7. Guitar Pick -P360.00" << endl <<endl;
cout<<"Choose from the available Music Equipments:";
cin>>equip;
if (equip=='1'){
cout<<"Enter your payment:";
cin>>pay5;
if (pay5==113){
cout<<"You have succesfully purchased Guitar String"<<endl;
}
else if (pay5>113){
pay5 -= 113;
cout<<"Your change is:"<<pay5<<endl;
}
else if(pay5<113)
{
cout<<"You do not have enough money"<<endl;
}
}
else if (equip=='2'){
cout<<"Enter your payment:";
cin>>pay5;
if (pay5==1600){
cout<<"You have succesfully purchased Headphones"<<endl;
}
else if (pay5>1600){
pay5 -= 1600;
cout<<"Your change is:"<<pay5<<endl;
}
else if(pay5<1600)
{
cout<<"You do not have enough money"<<endl;
}
}
else if (equip=='2'){
cout<<"Enter your payment:";
cin>>pay5;
if (pay5==1600){
cout<<"You have succesfully purchased Headphones"<<endl;
}
else if (pay5>1600){
pay5 -= 1600;
cout<<"Your change is:"<<pay5<<endl;
}
else if(pay5<1600)
{
cout<<"You do not have enough money"<<endl;
}
}
else if (equip=='3'){
cout<<"Enter your payment:";
cin>>pay5;
if (pay5==2800){
cout<<"You have succesfully purchased Amplifier"<<endl;
}
else if (pay5>2800){
pay5 -= 2800;
cout<<"Your change is:"<<pay5<<endl;
}
else if(pay5<2800)
{
cout<<"You do not have enough money"<<endl;
}
}
else if (equip=='4'){
cout<<"Enter your payment:";
cin>>pay5;
if (pay5==4750){
cout<<"You have succesfully purchased Digital Mixer"<<endl;
}
else if (pay5>4750){
pay5 -= 4750;
cout<<"Your change is:"<<pay5<<endl;
}
else if(pay5<4750)
{
cout<<"You do not have enough money"<<endl;
}
}
else if (equip=='5'){
cout<<"Enter your payment:";
cin>>pay5;
if (pay5==860){
cout<<"You have succesfully purchased Vocal Microphone"<<endl;
}
else if (pay5>860){
pay5 -= 860;
cout<<"Your change is:"<<pay5<<endl;
}
else if(pay5<860)
{
cout<<"You do not have enough money"<<endl;
}
}
else if (equip=='6'){
cout<<"Enter your payment:";
cin>>pay5;
if (pay5==537){
cout<<"You have succesfully purchased Guitar Tuner"<<endl;
}
else if (pay5>537){
pay5 -= 537;
cout<<"Your change is:"<<pay5<<endl;
}
else if(pay5<537)
{
cout<<"You do not have enough money"<<endl;
}
}
else if (equip=='7'){
cout<<"Enter your payment:";
cin>>pay5;
if (pay5==360){
cout<<"You have succesfully purchased Guitar Pick"<<endl;
}
else if (pay5>360){
pay5 -= 360;
cout<<"Your change is:"<<pay5<<endl;
}
else if(pay5<360)
{
cout<<"You do not have enough money"<<endl;
}
}
else {
cout<<"Invalid";
}
}
cout<<"\nWould you like to buy something else?"<<endl;
cout<<"Yes or No?"<<endl;
cin>>answer;
if (answer == "Yes"){
cout<<"Choose from the available categories"<<endl;
cout<<"[a] Acoustic Guitar"<<endl;
cout<<"[b] Electric Guitar"<<endl;
cout<<"[c] Drums"<<endl;
cout<<"[d] Piano"<<endl;
cout<<"[e] Music Equipments"<<endl;
cin >> music;
switch(music){
}
}
else if (answer == "No"){
cout<<"Thank you for visiting our shop come again";
}
}
Нужна петля, чтобы я мог продолжать покупать каждый раз, когда выбираю Да