Simple Calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ConsoleApplication1.cpp : Defines the entry point for the console application. | |
// | |
#include "stdafx.h" | |
#include <iostream> | |
#include <string> | |
using namespace std; | |
int _tmain() | |
{ | |
//assign an identifier for the numbers | |
float num1, num2, result; | |
char oper; | |
//the user input | |
cin >> num1 >> oper >> num2; | |
//Display line | |
cout << "*********************************************************" << endl; | |
//Check the user operator | |
if(oper == '+'){ | |
result = num1 + num2; | |
}else if(oper == '-'){ | |
result = num1 - num2; | |
} | |
else if(oper == '/'){ | |
result = num1 / num2; | |
} | |
else if(oper == '*'){ | |
result = num1 * num2; | |
} | |
else{ | |
cout << "Invalid operations...Please press enter to exit" << endl; | |
} | |
cout << result << endl; | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment