i am asked to write a program that reads in two arithmetic operators and a desired calculation result from those operations. The program will then search for combinations of +ve int a,b and c that will produce the desired result when the arithmetic operators are applied to them. The arithmetic operators allowed 4 input r multiplication (*), division (/), addition(+),n subtraction(-). Note that a,b,n c values range from 0-9. Division of the int values should be exact with no truncation error.
i hv done a program but, there are errors...so, help me by checking this,please...
cout << "Enter the desired result from the operations:";
cin >> sum ;
total = total + 1;
{
if (operator_1 == '+' ){
for (a = 0 ; a <= 9 ; a++);
for (b = 0 ; b <= 9 ; b++);
for (c = 0 ; c <= 9 ; c++);
}
else {
if (operator_1 == '-'){
for (a = 0 ; a <= 9 ; a++);
for (b = 0 ; b <= 9 ; b++);
for (c = 0 ; c <= 9 ; c++);
}
else {
if (operator_1 == '*'){
for (a = 0 ; a <= 9 ; a++);
for (b = 0 ; b <= 9 ; b++);
for (c = 0 ; c <= 9 ; c++);
}
else {
if (operator_1 == '/'){
for (a = 0 ; a <= 9 ; a++);
for (b = 0 ; b <= 9 ; b++);
for (c = 0 ; c <= 9 ; c++);
}
}
}
}
}
if (operator_2 == '+' ){
for (a = 0 ; a <= 9 ; a++);
for (b = 0 ; b <= 9 ; b++);
for (c = 0 ; c <= 9 ; c++);
}
else {
if (operator_2 == '-'){
for (a = 0 ; a <= 9 ; a++);
for (b = 0 ; b <= 9 ; b++);
for (c = 0 ; c <= 9 ; c++);
}
else {
if (operator_2 == '*'){
for (a = 0 ; a <= 9 ; a++);
for (b = 0 ; b <= 9 ; b++);
for (c = 0 ; c <= 9 ; c++);
}
else {
operator_2 == '/';
for (a = 0 ; a <= 9 ; a++);
for (b = 0 ; b <= 9 ; b++);
for (c = 0 ; c <= 9 ; c++);
}
}
}
}
if (arithmetic_operators = '+', '-', '*', '/'){
sum = a operator_1 b operator_2 c;
cout << a << operator_1 << b << operator_2 << c "=" << sum;
cout << "The total number of combination is" <<total<< ;
sum = a operator_1 b operator_2 c;
You can't do that...
You must do the calculations in the if-else statements depending on the user inputs...
Or better make a function that does that you pass 2 numbers and an operator sign and it does it for you.