😳 Simplest C++ calculator EVAR!

Posts 1–6 of 6 · Page 1 of 1
😳 Simplest C++ calculator EVAR!
For this tutorial you need:
Common C++ knowledge
A brain (very important)
And CodeBlocks or Visual Studio


Here is the code :

 
Code IS HERE
#include <iostream>
#include <windows.h>
using namespace std;

//Function prototype
int solve(int, int, char);

int main()
{
//Declare variables
int solution, num1, num2;
char oper;

//Output
system ( "color a" );
cout << " _________________00__________________" <<endl;
cout << " ________________0000_________________" <<endl;
cout << " _______________000000________________ " <<endl;
cout << " ____00_________000000__________00____ " <<endl;
cout << " _____0000______000000______00000_____ " <<endl;
cout << " _____000000____0000000___0000000_____ " <<endl;
cout << " ______000000___0000000_0000000_______ " <<endl;
cout << " _______0000000_000000_0000000________ " <<endl;
cout << " _________000000_00000_000000_________ " <<endl;
cout << " _0000_____000000_000_0000__000000000_ " <<endl;
cout << " __000000000__0000_0_000_000000000____ " <<endl;
cout << " _____000000000__0_0_0_000000000______ " <<endl;
cout << " _________0000000000000000____________ " <<endl;
cout << " ______________000_0_0000_____________ " <<endl;
cout << " ____________00000_0__00000___________ " <<endl;
cout << " ___________00_____0______00__________ " <<endl;
cout << "--------------Calculator-------------- By: WeedToThePeople" << endl;
system ( "color 2" );
cout << "DONT TYPE ANY LETTERS LIKE s BECAUSE THE PROGRAM WILL GO BERSERK!" << endl;
cout << "Syntax:\n" << endl;
cout << "1 + 3\n" << endl;
system ( "color 20" );
cout << "Operators: +, -, *, /\n" << endl;
cout << "Equation: ";

//Input
cin >> num1 >> oper >> num2;

//Solve and output
solution = solve(num1, num2, oper);
cout << "Answer: " << solution << endl;

//Pause [until enter key] and exit
cin.ignore(); //Enter key from last cin may be passed, ignore it.
cin.get();
return 0;
}

int solve(int num1, int num2, char oper)
{
//Switch oper
switch(oper)
{
case '+':
return num1 + num2;
case '-':
return num1 - num2;
case '*':
return num1 * num2;
case '/':
return num1 / num2;
default:
cout << "\nTold you!"<<endl;
cin >> num1 >> oper >> num2;
solve(num1, num2, oper);
}
}


Just C+P that into VS or CodeBlocks! DONE
Don't attack me for making a stupid tutorial some people came here to learn

NOTE: THIS THING CAN ONLY HANDLE 1 EQUATION AT ONE TIME!

[HTML]https://www.virustotal.com/en/file/2fc1d965d36a9b6d05d7870c421f476cbb9ffbfc7a0e41887b 62d3c158268ecd/analysis/1414248259/[/HTML] <---VIRUSTOTAL RESULTS 1/54

CalculatorFinal_mpgh.net.rar219 KB · 8 downloads 1/54 malicious
atoX functions work wonderfully.
I would not call this a tutorial. I would not call this learning. I would call this pure copy n paste.

You have no indent style in your code at all, which makes it very hard to read and looks like pure crap.
You've just added unnecessary comments which is quite obvious if you have common C++ knowledge. And by that you're calling this a tutorial?

Not attacking, just some feedback

Bai
Lol.

Code:
#include <stdio.h>

int n1, n2;
char op;

int Calc(){if(op=='+')return n1+n2; if(op=='-')return n1-n2; if(op=='/')return n1/n2; if(op=='*')return n1*n2; return -1;}

int main()
{
	while(op!='q')
	{
		printf("Enter Calculation:\n");
		scanf("%i %c %i", &n1, &op, &n2);
		printf("\nResult: %i\n", Calc());
	}
	return 0;
}
This one ain't got weed though... Still, 100x smaller and pure C.
Am I wrong or the division between 2 integers will return an integer too? I think that no one will want that.

Myaybe just add a .f
File appears safe.

/Approved
Posts 1–6 of 6 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us