 Output displayed twice | SoloLearn: Learn to code for FREE!

+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

11 Answers

New Answer

+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. 😰

+3

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

+3

Night_fury~ Sorry, I misunderstood the task, thanks for the additional explanation.

+2

have you tried snapping your fingers? *Jk*

+1

Why do you use as many as two cycles, when you can do through one conditional branching: "if...else"

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. 😕