Flock of Cats Rotating Header Image

C++

I have been playing around with C++ the last couple days, just because I am a big computer dork and to see what I can remember from back in high school computer science.

Here is my latest gem.


#include
#include
using namespace std;

float num1(0), num2 (0), answer (0);
string operate;

int main ()
{
cout << "Welcome to the calculator" << endl;
cout << "Enter the first number" << endl;
cin >> num1;
cout << endl << "Enter the second number." << endl;
cin >> num2;
cout << endl << "What operation would you like to perform? (+ - x /)" << endl;
cin >> operate;

if (operate == "x") {
answer=num1*num2;
cout << answer << endl << "You have multiplied " << num1 << " and " << num2 << ".";
}

else if (operate == "+") {
answer=num1+num2;
cout << answer << endl << "You have added " << num1 << " and " << num2 << ".";
}
else if (operate == "-") {
answer=num1-num2;
cout << answer << endl << "You have subtracted " << num2 << " from " << num1 << ".";
}
else if (operate == "/") {
answer=num1/num2;
cout << answer << endl << "You have divided " << num2 << " into " << num1 << ".";
}

else {
cout << "I'm sorry, you didn't enter a valid operation to perform" << endl;
}

}

Take that MS Calculator!

Related posts

Leave a Reply

Better Tag Cloud