"보험 가격 확인"을 다시 실행하기 위해 코드 끝에 'Y'를 입력 할 때 반복 구조를 만들려고합니다.사용자 입력을 기반으로 프로그램 루프를 처음부터 다시 시작하는 방법은 무엇입니까?
#include <iostream>
using namespace std;
int main() {
// Declaration of variables
char animal, status, continue_;
int i=0;
//Begin Loop
cout<<"Welcome to the Animal Insurance Company! What type of animal would you like to insure today: Enter D for Dog, C for Cat, B for Bird or R for Reptile: "<<endl;
cin>>animal;
if(animal=='D' || animal=='d') {
cout<<"You have selected a dog, has your dog been neutered? Enter Y for Yes or N for NO."<<endl;
cin>>status;
if(status=='Y' || status=='y')
cout<<"The insurance for your dog cost is $50."<<endl;
else if(status =='N' || status=='n')
cout<<"The insurance for your dog cost is $80."<<endl;
else
cout<<"Invalid Input, please type Y or N"<<endl;
}
else if (animal=='C' || animal=='c') {
cout<<"You have selected a cat, has your cat been neutered? Enter Y for Yes or N for NO."<<endl;
cin>>status;
if(status=='Y' || status=='y')
cout<<"The insurance for your cat cost is $40."<<endl;
else if(status =='N' || status=='n')
cout<<"The insurance for your cat cost is $60."<<endl;
else
cout<<"Invalid Input, please type Y or N"<<endl;
}
else if (animal=='B' || animal=='b' || animal=='R' || animal=='r')
cout<<"The insurance cost will be $10"<<endl;
else
cout<<"Invalid Input"<<endl;
cout<<"Do you want to insure another animal? Enter Y for Yes or N for NO."<<endl;
cin>>continue_;
if(continue_=='n' || continue_=='N')
cout<<"Thank you for using Animal Insurance Company"<<endl;
return 0;
}
코드 루프를 맨 처음으로 되돌리려면 어떻게해야합니까? 그럼 당신은 루프를 필요 스타터
나는 성가심이 싫지만, 작동하지 않는 방법이 있습니다. 지금 코드에 어떤 문제가 있습니까? – Krilla13
https://gyazo.com/9b286dff70380a8a67b1211c01a88bf7 - 여기 내 코드 이미지입니다. 그것은 작동하지만, "다른 동물을 지키기"끝에 "Y"를 타이핑하면 반복되지 않습니다. 다른 멤버가 작동하는 것 같은 goto loop가 있지만, 교수님이 그 방법을 가르쳐주지 않으므로 사용하기를 주저합니다. – Krilla13
값을 비교할 때 하나만이 아니라 2 개의 등호가 필요합니다. 당신은 당신의 코드의 14 번째 라인에서 이것을했습니다. – Matt