Loop
Loop
int main()
{
char op,ch;
int num1, num2, answer, counter = 0;
while (counter <=0)
{
cout <<"+ for addition"<<endl;
cout <<"- for subtraction"<<endl;
cout <<"* for multiplication"<<endl;
cout <<"/ for division" <<endl;
cin>>op;
if (op == '+')
{
cout<<"Enter 1st number: ";
cin>>num1;
cout<<"Enter 2nd number: ";
cin>> num2;
answer = num1 + num2;
cout<<"The answer is: "<<answer<<endl;
cout<<"Do you want to try again? (y/n): ";
cin>>ch;
if (ch=='y' || ch == 'Y')
{
counter = 0;
}
else
{
cout<<"Thank you";
counter++;
break;
}
}
}else
{
cout <<"Wrong Choice"<<endl;
cout<<"Do you want to try again? (y/n): ";
cin>>ch;
if (ch=='y' || ch == 'Y')
{
counter = 0;
}
else
{
cout<<"Thank you";
counter++;
break;
}
}
}
return 0;
}