Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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