In: Computer Science
C++
Follow Instructions Please
By placing a break in the IIF statement you are using it to force an exit from the WHILE loop. The break statement is only allowed with the SELECT/CASE statement. Also, don't use one structure to force an exit from another. Use the logic from the WHILE loop to end by removing the IF with the break
#include <iostream> using namespace std; bool IsMultiple(int,int); int main() { char choice; int n1,n2; bool result; int test = 0; cout << "Do You Want to Play? (Y/N)" << endl; choice = cin.get(); while(choice == 'Y') { cout << "Test" << ++test << endl; cout << "X: "; cin >> n2; cout << "Y: "; cin >> n1; result = IsMultiple(n2,n1); cout << result << endl; cout << "Do You Want to Play Again" << endl; cin >> choice; if(choice == 'N') { break; } } } bool IsMultiple(int x, int y) { if(x % y == 0) { cout << "Number " << x << " is divisible by " << y << endl; return true; } else { cout << "Number " << x << " is not divisible by " << y << endl; return false; } }
`Hey,
Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries
#include <iostream>
using namespace std;
bool IsMultiple(int,int);
int main()
{
char choice;
int n1,n2;
bool result;
int test = 0;
cout << "Do You Want to Play? (Y/N)" << endl;
choice = cin.get();
while(choice == 'Y')
{
cout << "Test" << ++test << endl;
cout << "X: ";
cin >> n2;
cout << "Y: ";
cin >> n1;
result = IsMultiple(n2,n1);
cout << result << endl;
cout << "Do You Want to Play Again" << endl;
cin >> choice;
while(choice!='Y'&&choice!='N')
{
cout<<"Invalid choice!!"<<endl;
cout << "Do You Want to Play Again" << endl;
cin >> choice;
}
}
return 0;
}
bool IsMultiple(int x, int y)
{
if(x % y == 0)
{
cout << "Number " << x << " is divisible by "
<< y << endl;
return true;
}
else
{
cout << "Number " << x << " is not divisible by "
<< y << endl;
return false;
}
}
Kindly revert for any queries
Thanks.