Change C Code User Prompt Y N Instead 1 Continue Include Using Namespace Std Bool Ismulitp Q37225903

Change this C++ code so the user is prompt with(Y or N) instead of 1 to continue.

#include <iostream>

using namespace std;
bool isMulitple(int n1,int n2){
return n1%n2==0;
}
int main()
{
int c=1;
int n1,n2;
while(c==1){
cout<<“Enter 2 numbers: “;
cin>>n1;
cin>>n2;
if(isMulitple(n1,n2))
cout<<n1<<“,”<<n2<<” are mulitples of eachothern”;
else
cout<<n1<<“,”<<n2<<” are not mulitple ofeach other n”;
cout<<“Press 1 to continue ,any other key to exit: “;<—– Change this to (Y or N)prompt
cin>>c;
}
}


Answer


#include <iostream>using namespace std;bool isMulitple(int n1,int n2){return n1%n2==0;}int main(){char c = ‘Y’;int n1,n2;while(c==’Y’){cout<<“Enter 2 numbers: “;cin>>n1;cin>>n2;if(isMulitple(n1,n2))cout<<n1<<“,”<<n2<<” are mulitples of each othern”;elsecout<<n1<<“,”<<n2<<” are not mulitple of each other n”;cout<<“Press (Y or N) to continue ,any other key to exit: “; cin>>c;}}

nter 2 numbers: 34 3.4 are not mulitple of each other Press <Y or N> to continue ,an y other ke to exit: Y Enter 2 numbers 4

nter

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.