+13

# Output displayed twice

In the code below the output is displayed twice. Can somebody please tell me why it is working this way and how to fix it. https://code.sololearn.com/ccRi7rCk7HkA/?ref=app

+5

// Make something like the following // 1. Remove else statement // 2. When you find at least one pair exit the program // 3. in case that the program does not find any pair , raise message for(int i=1;i<p;i++){ for (int j=1;j<p;j++){ x=i*j; if(p==x){ y=i+j; if(s==y){ cout << "\n" << s << " and " << p << " are sum and product of " << i << " and " << j << endl; return 0; } } } } cout << s << " and " << p << " are invalid input."<< endl;

+11

Vasiliy I am new to coding. I was just trying to do it correctly. Can you code it and explain ? (coditional branch )

+9

This is awesome bro.. 😍😍 Bennett Post . but there is one thing if we check for 4,5 i.e 1*4=4 & 1+4=5 then it is giving invalid output ..

+8

Vasiliy it is not working properly.. I tried with 5,6 because that was the example given in question. something is wrong 🤔

+8

🤦🏻‍♂️ 5 is sum of two numbers and 6 is product of same two numbers .. i.e 2,3 . I think I didnt wrote question clearly. 😰

+8

lol yes 😁

+3

In this case, it is sufficient in the proposed Prokopios Poulimenos code to change the variable "p" in cycles to "s".

+3