Skip to content

Instantly share code, notes, and snippets.

@devmike01
Last active May 23, 2018 20:13
Show Gist options
  • Save devmike01/5a4f80c09e13e9e782bec723740265cd to your computer and use it in GitHub Desktop.
Save devmike01/5a4f80c09e13e9e782bec723740265cd to your computer and use it in GitHub Desktop.
Simple Calculator
// 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