Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SimpleCalc.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <windows.h>
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- //Variables
- int fnum;
- int snum;
- int result;
- char sym;
- char st();
- char loop = 'y';
- char ff();
- int calc();
- int wait;
- //Main stuff
- int main(int nNumberofArgs, char*
- pszArgs[])
- {
- SetConsoleTitle( TEXT( "SimpleCalc" ) );
- cout << ("Welcome to SimpleCalc!") <<endl;
- cout << ("Project By: Christopher Altig!") <<endl;
- while (loop == 'y')
- {
- ff();
- if (sym == '*')
- {
- result = fnum * snum;
- cout << "Answer:" << result <<endl;
- st();
- }
- else if (sym == '/')
- {
- result = fnum / snum;
- cout << "Answer:" << result <<endl;
- st();
- }
- else if (sym == '-')
- {
- result = fnum - snum;
- cout << "Answer:" << result <<endl;
- st();
- }
- else if (sym == '+')
- {
- result = fnum + snum;
- cout << "Answer:" << result <<endl;
- st();
- }
- else if (sym == '%')
- {
- result = snum % fnum;
- cout << "Answer:" << result <<endl;
- st();
- }
- }
- return 0;
- }
- //Down here V V V
- char st()
- {
- cout << ("Do another calculation (Y/N): ");
- cin >> loop;
- if (loop == 'n')
- {
- exit (EXIT_SUCCESS);
- }
- else if (loop !='n' && loop !='y')
- {
- cout << ("Error: Invalid Character!") <<endl;
- st();
- }
- return 0;
- }
- char ff()
- {
- cout << "Symbol here:"; cin >> sym;
- if (sym == '*' || sym == '/' || sym == '+' || sym == '-' || sym == '%')
- {
- calc();
- }
- else
- {
- cout << ("Error: Invalid Character!") <<endl;
- ff();
- }
- return 0;
- }
- int calc()
- {
- snum = 0;
- fnum = 0;
- system("CLS");
- cout << "Number 1:"; cin >> fnum;
- cout << "Number 2:"; cin >> snum;
- if (snum >= 0 || fnum >= 0)
- {
- cout << ("Error: Invalid Number!") << endl;
- wait = 0;
- while (wait <= 5)
- {
- wait++;
- }
- system("CLS");
- calc();
- }
- else
- {
- ff();
- }
- return 0;
- }
- //Up there ^ ^ ^
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement