#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
// Void means the function doesn't return a value to the caller
// Int means the function returns a integer value to the caller
// adds number_1 and number_2
int add(int x, int y)
{
cout << x + y << endl;
return 0;
}
// subtracts number_1 and number_2
int subtract(int x, int y)
{
cout << x - y << endl;
return 0;
}
// divides number_1 and number_2
int divide(int x, int y)
{
cout << x / y << endl;
return 0;
}
// multiplys number_1 and number_2
int multiply(int x, int y)
{
cout << x * y << endl;
return 0;
}
int main()
{
int number_1;
int number_2;
string operation;
cout << "Enter a number: ";
cin >> number_1;
cout << "Enter another number: ";
cin >> number_2;
cout << "What operation do you want to do?: ";
cin >> operation;
// checks if the users typed in "add" and if so adds number_1 and number_2
if (operation == "add")
{
add(number_1, number_2);
}
// checks if the users typed in "subtract" and if so subtracts number_1 and number_2
else if (operation == "subtract")
{
subtract(number_1, number_2);
}
// checks if the users typed in "divide" and if so divides number_1 and number_2
else if (operation == "divide")
{
divide(number_1, number_2);
}
// checks if the users typed in "multiply" and if so multiplys number_1 and number_2
else if (operation == "multiply")
{
multiply(number_1, number_2);
}
// if the above checks fail this message will be displayed to the user
else
{
cout << "Please input a valid opeartor!" << endl;
// re-runs through the programm
main();
}
cin.clear(); // reset any error flags
cin.ignore(32767, '\n'); // ignore any characters in the input buffer until we find an enter character
cin.get(); // get one more char from the user
// returns 0
return 0;
}
Just a simple calculator in C++. Since i'm new to the language it's not the best and can easily be broken but meh it's a start.
I'm rather new to C# but I'm learning the basics from http://csharp.net-tutorials.com After I've got a grasp of the basic I'll most likely watch YouTube videos to expand my knowledge.