Greetings! :)
Can you please tell me why does windows says ".exe has stopped running" after i give values for the two int that goes to cin?
(I am using codeblocks)
The program has to decide if 2 given numbers are friendly or not.
Thank you for your help!
#include <iostream>
usingnamespace std;
bool friendly (int a, int b){
bool def=false;
int suma=0;
int sumb=0;
for (int i=0; i<a; i++){
if((a%i)==0){
int suma=suma+1;
}
}
for (int i=0; i<b; i++){
if((b%i)==0){
int sumb=sumb+1;
}
}
if (sumb==a && suma==b){
def=true;
}
return def;
}
int main()
{
int a,b;
cout << "Please give two integer numbers separated by a space" << endl;
cin>> a >> b;
if (friendly(a,b)==true){
cout<<"The two given numbers are friendly!"<<endl;
}
else{
cout<<"The two given numbers are not friendly!"<<endl;
}
return 0;
}