### Algebra program problem

hello,

I am making a program where you input two numbers and outputs two numbers which
are combined number1 and timed number two

for example
input: 7 12
output:3 4

the problem is when your iput is a positive and then a negative

for example
input: 7 -12

you get no answer. this is the only combination that doesn't work.
-- -+ ++ works.

can somewone plz tell me whats wrong with the code
and sorry if the code is sloppy i am a beginner.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152`` ``````#include "stdafx.h" #include using namespace std; int main() { while(true) { bool loop=true; int n1; int n2; cin >> n1 >> n2; int n3=-100; int n4=-100; for(bool loop=true;loop=true; n3++) { for(; n4<30; n4++) { if(n3+n4==n1 && n3*n4==n2) { const char* plusSignN3 = ""; const char* plusSignN4 = ""; if(n3>0) { plusSignN3="+"; } if(n3>0) { plusSignN4="+"; } cout << n3 << " " << n4 << endl; loop=false; } } n4=0; } cin >> n1; } }``````
I think you need better checks. I believe this program tries to find two numbers of which the sum equals the first number and the product equals the second number. I have tried to make it so that if there is no solution, we get back to input.

 ``12345678910111213141516171819202122232425262728293031323334353637`` ``````#include int main() { using namespace std; while(true) { int n1(0), n2(0); cin >> n1 >> n2; int n3(-100), n4(-100); for(bool loop = true; (n3 < n1 || n3 < n2) && loop; ++n3) // You used assignment, you should use == to check for equality. { for(; n4 < n1 || n4 < n2; ++n4) { if((n3 + n4) == n1 && (n3 * n4) == n2) // http://en.cppreference.com/w/cpp/language/operator_precedence { const char *plusSignN3 = ""; const char *plusSignN4 = ""; if(n3 > 0) { plusSignN3 = "+"; plusSignN4 = "+"; } cout << n3 << " " << n4 << endl; loop = false; break; } } n4=0; } //cin >> n1; // Why are you asking for n1 when you're gonna ask it again? } } ``````
Topic archived. No new replies allowed.