a bit confusing!!!

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

#include <iostream.h>
#include <conio.h>
#include <math.h>

void main()
{
int a, b, c, sum, total;
char operator_1, operator_2, arithmetic_operators;
total = sum = 0 ;

cout << "Enter two operators:";
cin >> operator_1 >> operator_2 ;

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<< ;

else {
cout << "Wrong operator(s)! Please try again.";

}
getch();
}
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.
Last edited on
Topic archived. No new replies allowed.