Ahsanfk said:
too long codes not have any short codes?
Well it dosent matter how long code is,
if u understand the code u will find it
very easy, anyway here is simplest
as well as commented code, all u gta
do is add cout statements where ever u
want to;
Code:
#include <iostream> // handle input and outputs
using namespace std; // using std, to avoid using std:: each time
int main() // function starts
{
double MyVar, MyVar2, Result; // Declared variables
char Sign; // to handle calculations
cin >> MyVar >> Sign >> MyVar2; // Getting input from user.
if (Sign == '+') // Testing condition using
{
Result = MyVar + MyVar2; // do calculation according to condition
}
else if (Sign == '-')
{
Result = MyVar - MyVar2;
}
else if (Sign == '*')
{
Result = MyVar * MyVar2;
}
else if (Sign == '/')
{
Result = MyVar / MyVar2;
}
cout << "Answer: " << Result << endl; // finally print result of the calculations to screen
system ("PAUSE"); // Pause the screen so that user can see the answer at end
return 0;
}
In case u dont know, writing after // is jst to tell u what it is,
that is not included in code.
if u r still confused then try this:
Code:
#include <iostream>
using namespace std;
int main() { double MyVar, MyVar2, Result;
char Sign;
cin >> MyVar >> Sign >> MyVar2;
if (Sign == '+') {Result = MyVar + MyVar2; }
else if (Sign == '-') { Result = MyVar - MyVar2;}
else if (Sign == '*') {Result = MyVar * MyVar2;}
else if (Sign == '/') {Result = MyVar / MyVar2;}
cout << "Answer: " << Result << endl;
system ("PAUSE");
return 0; }
-Saif
Bookmarks