+ 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

20th May 2019, 7:22 AM
Night_fury~
Night_fury~ - avatar
11 odpowiedzi
+ 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;
20th May 2019, 8:24 AM
Prokopios Poulimenos
Prokopios Poulimenos - avatar
+ 11
Vasiliy I am new to coding. I was just trying to do it correctly. Can you code it and explain ? (coditional branch )
20th May 2019, 3:52 PM
Night_fury~
Night_fury~ - avatar
+ 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 ..
21st May 2019, 3:30 AM
Night_fury~
Night_fury~ - avatar
+ 8
Vasiliy it is not working properly.. I tried with 5,6 because that was the example given in question. something is wrong 🤔
21st May 2019, 12:17 AM
Night_fury~
Night_fury~ - avatar
+ 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. 😰
21st May 2019, 3:08 AM
Night_fury~
Night_fury~ - avatar
+ 8
lol yes 😁
21st May 2019, 3:36 AM
Night_fury~
Night_fury~ - avatar
+ 3
In this case, it is sufficient in the proposed Prokopios Poulimenos code to change the variable "p" in cycles to "s".
20th May 2019, 11:47 AM
Solo
Solo - avatar
+ 3
Night_fury~ Sorry, I misunderstood the task, thanks for the additional explanation.
21st May 2019, 6:37 AM
Solo
Solo - avatar
+ 2
have you tried snapping your fingers? *Jk*
22nd May 2019, 3:31 AM
Radu Baloi
Radu Baloi - avatar
+ 1
Why do you use as many as two cycles, when you can do through one conditional branching: "if...else"
20th May 2019, 3:05 PM
Solo
Solo - avatar
0
According to the task: "Two numbers are given one is the sum of two integers and another is product of the same integers. FInd the two integers." 5, 6 - invalid input. 😕
21st May 2019, 12:29 AM
Solo
Solo - avatar