Bug fixes
This commit is contained in:
parent
4fc0aad664
commit
47b4af92e5
|
@ -2,7 +2,7 @@
|
|||
#include <functional>
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include "NewCalcFunctions.h"
|
||||
#include "CalculatorFunctions.h"
|
||||
double total_num;
|
||||
int end_option;
|
||||
int option;
|
||||
|
@ -17,24 +17,21 @@ int main()
|
|||
switch (option)
|
||||
{
|
||||
case 1:
|
||||
total_num = math("Addition", std::plus<>(), false);
|
||||
std::cout << total_num << '\n';
|
||||
total_num = math("Addition", std::plus<>(), false, " + ");
|
||||
break;
|
||||
case 2:
|
||||
total_num = math("Subtraction", std::minus<>(), false);
|
||||
std::cout << total_num << "\n";
|
||||
total_num = math("Subtraction", std::minus<>(), false, " - ");
|
||||
|
||||
break;
|
||||
case 3:
|
||||
total_num = math("Division", std::divides<>(), false);
|
||||
std::cout << total_num << "\n";
|
||||
total_num = math("Division", std::divides<>(), false, " / ");
|
||||
|
||||
break;
|
||||
case 4:
|
||||
total_num = math("Multiplication", std::multiplies<>(), false);
|
||||
std::cout << total_num << "\n";
|
||||
total_num = math("Multiplication", std::multiplies<>(), false, " X ");
|
||||
break;
|
||||
case 5:
|
||||
total_num = square_root("Square root", false);
|
||||
std::cout << total_num << "\n";
|
||||
break;
|
||||
}
|
||||
std::cout << "Please choose an option from the list:" << '\n';
|
||||
|
@ -53,24 +50,19 @@ int main()
|
|||
switch (option2)
|
||||
{
|
||||
case 1:
|
||||
total_num = math("Add", std::plus<>(), true);
|
||||
std::cout << total_num << '\n';
|
||||
total_num = math("Add", std::plus<>(), true, " + ");
|
||||
break;
|
||||
case 2:
|
||||
total_num = math("Subtract", std::minus<>(), true);
|
||||
std::cout << total_num << "\n";
|
||||
total_num = math("Subtract", std::minus<>(), true, " - ");
|
||||
break;
|
||||
case 3:
|
||||
total_num = math("Divide", std::divides<>(), true);
|
||||
std::cout << total_num << "\n";
|
||||
total_num = math("Divide", std::divides<>(), true, " / ");
|
||||
break;
|
||||
case 4:
|
||||
total_num = math("Multiply", std::multiplies<>(), true);
|
||||
std::cout << total_num << "\n";
|
||||
total_num = math("Multiply", std::multiplies<>(), true, " X ");
|
||||
break;
|
||||
case 5:
|
||||
total_num = square_root("Square root", true);
|
||||
std::cout << total_num << "\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
#include "NewCalcFunctions.h"
|
||||
#include <iostream>
|
||||
#include <functional>
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include "CalculatorFunctions.h"
|
||||
using namespace std;
|
||||
double math(std::string text, std::function<double(double, double)> code, bool use_last_num)
|
||||
double math(std::string text, std::function<double(double, double)> code, bool use_last_num, std::string math_symbol)
|
||||
{
|
||||
double total_num;
|
||||
double num1;
|
||||
double num2;
|
||||
double total_num = 0;
|
||||
double num1 = 0;
|
||||
double num2 = 0;
|
||||
std::ofstream num_write;
|
||||
num_write.open("last-total-num.txt", ios::out);
|
||||
if (!use_last_num)
|
||||
|
@ -21,11 +21,10 @@ double math(std::string text, std::function<double(double, double)> code, bool u
|
|||
total_num = code(num1, num2);
|
||||
num_write << total_num;
|
||||
num_write.close();
|
||||
std::cout << num1 << math_symbol << num2 << " = " << total_num << "\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
num_write << total_num;
|
||||
num_write.close();
|
||||
std::ifstream num_read;
|
||||
num_read.open("last-total-num.txt", ios::in);
|
||||
double last_num;
|
||||
|
@ -36,6 +35,7 @@ double math(std::string text, std::function<double(double, double)> code, bool u
|
|||
std::cout << "Please enter the number here: \n";
|
||||
std::cin >> num2;
|
||||
total_num = code(num2, last_num);
|
||||
std::cout << num1 << math_symbol << num2 << " = " << total_num << "\n";
|
||||
}
|
||||
return total_num;
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ double square_root(std::string text, bool use_last_num)
|
|||
double sqrt_num;
|
||||
std::cin >> sqrt_num;
|
||||
total_num = sqrt(sqrt_num);
|
||||
std::cout << "The square root of " << sqrt_num << " = " << total_num;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -57,6 +58,7 @@ double square_root(std::string text, bool use_last_num)
|
|||
double last_num;
|
||||
num_read >> last_num;
|
||||
total_num = sqrt(last_num);
|
||||
std::cout << "The square root of " << last_num << " = " << total_num;
|
||||
}
|
||||
return total_num;
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <functional>
|
||||
double math(std::string text, std::function<double(double, double)> code, bool use_last_num);
|
||||
double math(std::string text, std::function<double(double, double)> code, bool use_last_num, std::string math_symbol);
|
||||
double square_root(std::string, bool use_last_num);
|
15
Installer.sh
15
Installer.sh
|
@ -1,9 +1,20 @@
|
|||
#!/bin/bash
|
||||
echo "Compiling..."
|
||||
clang++ NewCalc.cpp NewCalcFunctions.cpp -std=c++17 -o Calculator
|
||||
clang++ Calculator.cpp CalculatorFunctions.cpp -std=c++17 -o Calculator
|
||||
echo "Done!"
|
||||
echo "Cleaning up..."
|
||||
sleep 1
|
||||
mv Calculator ${HOME}/Desktop
|
||||
cd .git/
|
||||
rmdir --ignore-fail-on-non-empty ${HOME}/Terminal-Based-Calculator/.git
|
||||
rmdir --ignore-fail-on-non-empty ${HOME}/Terminal-Based-Calculator
|
||||
echo "Done! Now enjoy your calculator :)!"
|
||||
echo "Done!"
|
||||
echo "Now enjoy your calculator :)!"
|
||||
echo "Closing in:"
|
||||
echo "3"
|
||||
sleep 1
|
||||
echo "2"
|
||||
sleep 1
|
||||
echo "1"
|
||||
sleep 1
|
||||
exit
|
||||
|
|
Reference in a new issue