I'm trying to write a program that can do the following:
it takes 3 inputs: ex. 2000, 1000, 1000
it takes one more input called the total: ex. 6000
it should output that (2)*(2000)+(1)*(1000)+(1)*(1000)=6000 (so x=2, y=1, z=1)
the program should be able to find what combination of the 3 inputs will produce the total (it should be able to find all combinations). in this case it's easy because (2)*(2000)+1000+1000=6000 but I'm trying to do more complicated numbers that would be declared as "double" and not "int."
this is what I've got, I'm at work and we don't have C++ so I can't try it yet but can someone please tell me if this would work? and if not, can someone help me please?! thanks!
double n1, n2, n3;
cout << "enter 3 values" << endl;
cin >> n1 >> n2 >> n3;
double total;
cout << "enter a value for the total: " << endl;
cin >> total;
if (n1+n2+n3=total) {
cout << n1 << "+" << n2 << "+" << n3 << " = " << total;
return 0;
}
if (n1+n2=total) {
cout << n1 << "+" << n2 << " = " << total;
return 0;
}
if (n1+n3=total) {
cout << n1 << "+" << n3 << " = " << total;
return 0;
}
if (n2+n3=total) {
cout << n2 << "+" << n3 << " = " total;
return 0;
}
else {
int x, y, z;
(n1)*(x)+(n2)*(y)+(n3)*(z) = total;
cout << "x = " << x << ", y = " << y << ", z = " << endl;
}
return 0;
}
also, I don't know how to get it to output all possible combinations because like with the example before, if you have 2000, 1000, and 1000 and your total is 6000, you could have (3)*(2000) or (6)*(1000) or (2)(2000)+(1)(1000)+(1)(1000), etc.