{
using namespace std;
cout << "Enter a Number";
double dX;
cin >> dX;
cout << "Enter another Number";
double dY;
cin >> dY;
cout << "Enter a Symbol";
char symbol;
cin >> symbol;
if (symbol == '+');
cout << dX << " + " << dY << " Is " << dX + dY << endl;
if ('-' == symbol);
cout << dX << " - " << dY << " Is " << dX - dY << endl;
if (symbol == '*');
cout << dX << " * " << dY << " Is " << dX * dY << endl;
if (symbol == '/');
cout << dX << " / " << dY << " Is " << dX / dY << endl;
return 0 ;
}
Pretty new to C++ and I'm learning off the tuts at learn C++. Anyways, i was doing the comprehensive quiz,(I'm using visual studio express 2k12) and I finished the task quite simply. The program runs but displays all of the math and not the math that was requested.
For example, I can input any two numbers within the double and then input a symbol; the program then shows all of the math of the two numbers, (x+y, x*y, x-y, x/y).
How do I get it to show me only the symbol that is imputed.
Thanks :)
if (condition) // no semicolon here
statement; // for only one statement
or
if (condition) {
// for multiple statements
}
what your code was doing was, it terminated the "if" statement once it reached the semicolon. All the conditional statements were executed like normal statements without the "if condition".