Thank you to all who tried solving this problem and giving out suggestions!
Scroll down to see the solution.
EDIT: I used my Arduino on Autodesk Tinkercad, not on the actual Arduino, which might be the reason for my errors.
Whenever I try to test my calculator to see if it is working, for some reason, when it gets to the part where it performs a calculation in my code, the part where it prints out the equation with the numbers and the answer just disappears to no avail.
float b;
String mode;
String choice;
float e = 2.718281828459045;
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("Welcome to Alculus Calculator!");
Serial.println("Pick a math operation to calculate: '+', '-', '*', '/', '%', '^', '!', 'sqrt()', 'root()', 'sin()', 'cos()', 'tan()', 'csc()', 'sec()', 'cot()', 'arcsin()', 'arccos()', 'arctan()', 'arccsc()', 'arcsec()', 'arccot()', 'log()', 'ln()', Combinatiorics 'nCr', Permutation 'nPr', Solve for x in a polynomial 'Px', Polynomial Multiplication 'Pm', Polynomial Divison 'Pd', Solve for Arithmetic Series 'A', Solve for Geometric Series 'G'");
while (Serial.available() == 0){}
String c = Serial.readString();
if (c == "+" || c == "-" || c == "*" || c == "/" || c == "%" || c == "^" || c == "!" || c == "sqrt()" || c == "sin()" || c == "cos()" || c == "tan()" || c == "csc()" || c == "sec()" || c == "cot()" || c == "arcsin()" || c == "arccos()" || c == "arctan()" || c == "arccsc()" || c == "arcsec()" || c == "arccot()"){
if (c == "sin()" || c == "cos()" || c == "tan()" || c == "csc()" || c == "sec()" || c == "cot()" || c == "arcsin()" || c == "arccos()" || c == "arctan()" || c == "arccsc()" || c == "arcsec()" || c == "arccot()"){
Serial.println("Would you like your |number (for non-inverse trig functions)/answer (for inverse trig functions)| in 'radians' or 'degrees'? If you do not type a valid answer, your number will be in radians. Type here: ");
while (Serial.available() == 0){}
mode = Serial.readString();
}Serial.println("Type a number here: ");
while (Serial.available() == 0){}
float a = Serial.parseFloat();
if (!(c == "!" || c == "sqrt()" || c == "sin()" || c == "cos()" || c == "tan()" || c == "csc()" || c == "sec()" || c == "cot()" || c == "arcsin()" || c == "arccos()" || c == "arctan()" || c == "arccsc()" || c == "arcsec()" || c == "arccot()")){
Serial.println("Type another number here: ");
while (Serial.available() == 0){}
b = Serial.parseFloat();
}if (c == "+"){
Serial.println(String(a) + "+" + String(b) + "=" + String(a+b));
}if (c == "-"){
Serial.println(String(a) + "-" + String(b) + "=" + String(a-b));
}if (c == "*"){
Serial.println(String(a) + "*" + String(b) + "=" + String(a*b));
}if (c == "/"){
if (b != 0){
Serial.println(String(a) + "/" + String(b) + "=" + String(a/b));
}else{
Serial.println("You cannot divide a number by 0. Wait for 3 seconds.");
delay(3000);
Serial.println("\n\n");
}
}if (c == "%"){
Serial.println(String(a) + "%" + String(b) + "=" + String( float(long(a*pow(10, 2))%long(b*pow(10, 2)))/pow(10, 2) ));
}if (c == "^"){
Serial.println(String(a) + "^" + String(b) + "=" + String(pow(a, b)));
}if (c == "!"){
Serial.println(String(a) + "!" + "=" + String(gamma(a)));
}if (c == "sqrt()"){
Serial.println("sqrt(" + String(a) + ")=" + String(squareRoot(a)));
}if (c == "sin()"){
Serial.println("sin(" + String(a) + ")=" + String(sine(a)));
}if (c == "cos()"){
Serial.println("cos(" + String(a) + ")=" + String(cosine(a)));
// sine(a+pi/2)
}if (c == "tan()"){
Serial.println("tan(" + String(a) + ")=" + String(sine(a)/cosine(a)));
}if (c == "csc()"){
Serial.println("csc(" + String(a) + ")=" + String(1/sine(a)));
}if (c == "sec()"){
Serial.println("sec(" + String(a) + ")=" + String(1/cosine(a)));
}if (c == "cot()"){
Serial.println("cot(" + String(a) + ")=" + String(cosine(a)/sine(a)));
}if (c == "arcsin()"){
Serial.println("arcsin(" + String(a) + ")=" + String(arcS(a)));
}if (c == "arccos()"){
Serial.println("arccos(" + String(a) + ")=" + String(PI/2-arcS(a)));
}if (c == "arctan()"){
Serial.println("arctan(" + String(a) + ")=" + String(arcT(a)));
//arcS(a/squareRoot(1 + x*x))
}if (c == "arccsc()"){
Serial.println("arccsc(" + String(a) + ")=" + String());
}if (c == "arcsec()"){
Serial.println("arcsec(" + String(a) + ")=" + String());
}if (c == "arccot()"){
Serial.println("arccot(" + String(a) + ")=" + String());
}
}else{
Serial.println("\n\n\nPlease type a valid math operation that is given to you by the calculator. Wait for 3 seconds.");
delay(3000);
Serial.println("\n\n");
}Serial.println("\n");
}
float squareRoot(float n){
float i;
while ((i*i)<n){
if ((i*i)<n){
i += 0.01;
}
}if ( abs((n-i*i)) < abs((n-(i-0.01)*(i-0.01))) ){
return i;
}else{
return i-0.01;
}
}
float sine(float n){
float ans;
float place;
while (n > PI){
n -= PI;
}while (n < -1*PI){
n += PI;
}for (int i=1; i<=21; i+=2) {
place = pow(n, i);
for (int j=1; j<=i; j++) {
place = place/j;
}if (((i+1)/2)%2 == 0){
ans += place;
}else{;
ans -= place;
}
}return ans;
}
float cosine(float n){
float ans;
float place;
for (int i=0; i<=20; i+=2) {
place = pow(n, i);
for (int j=1; j<=i; j++) {
place = place/j;
}if ((i/2)%2 == 1){
ans += place;
}else{;
ans -= place;
}
}return ans;
}
float arcS(float n){
float ans;
float place;
for (int i=1; i<=21; i+=2) {
place = pow(n, i)/i;
for (int j=1; j<=i-1; j++) {
if (j%2 == 1){
place *= j;
}else{
place /= j;
}
}ans += place;
}return ans;
}
float arcT(float n){
float ans;
float place;
if (abs(n) < 1){
return sine(n);
}else{
if (n > 0){
ans = PI/2;
}else{
ans = -1*PI/2;
}for (int i=1; i<=21; i+=2) {
place = 1/(i*pow(n, i));
if (((i+1)/2)%2 == 1){
ans += place;
}else{;
ans -= place;
}
}return ans;
}
}
float gamma(float n){
n += 1;
int g = 7;
float lanczos[] = {
0.99999999999980993,
676.5203681218851,
-1259.1392167224028,
771.32342877765313,
-176.61502916214059,
12.507343278686905,
-0.13857109526572012,
9.9843695780195716e-6,
1.5056327351493116e-7};
if (n < 0.5){
return PI/(sine(PI*n)*gamma(1-n));
}else{
n -= 1;
float place = lanczos[0];
for (int i=1; i<=9; i++){
place += lanczos[i]/(n+i);
}float v = n + g + 0.5;
return squareRoot(2*PI)*pow(v, n+0.5)*pow(e, -1*v)*place;
}
}
For example, if I wanted to do a simple math operation such as "3.00+3.00", I would just get "=6.00" instead of "3.00+3.00=6.00".
If I wanted to do a complicated math operation such as "sin(55.3)", I would get absolutely nothing instead of "sin(55.3)=-0.95"
Here is the code where it cuts off the text:
if (c == "+"){
Serial.println(String(a) + "+" + String(b) + "=" + String(a+b));
}if (c == "-"){
Serial.println(String(a) + "-" + String(b) + "=" + String(a-b));
}if (c == "*"){
Serial.println(String(a) + "*" + String(b) + "=" + String(a*b));
}if (c == "/"){
if (b != 0){
Serial.println(String(a) + "/" + String(b) + "=" + String(a/b));
}else{
Serial.println("You cannot divide a number by 0. Wait for 3 seconds.");
delay(3000);
Serial.println("\n\n");
}
}if (c == "%"){
Serial.println(String(a) + "%" + String(b) + "=" + String( float(long(a*pow(10, 2))%long(b*pow(10, 2)))/pow(10, 2) ));
}if (c == "^"){
Serial.println(String(a) + "^" + String(b) + "=" + String(pow(a, b)));
}if (c == "!"){
Serial.println(String(a) + "!" + "=" + String(gamma(a)));
}if (c == "sqrt()"){
Serial.println("sqrt(" + String(a) + ")=" + String(squareRoot(a)));
}if (c == "sin()"){
Serial.println("sin(" + String(a) + ")=" + String(sine(a)));
}if (c == "cos()"){
Serial.println("cos(" + String(a) + ")=" + String(cosine(a)));
// sine(a+pi/2)
}if (c == "tan()"){
Serial.println("tan(" + String(a) + ")=" + String(sine(a)/cosine(a)));
}if (c == "csc()"){
Serial.println("csc(" + String(a) + ")=" + String(1/sine(a)));
}if (c == "sec()"){
Serial.println("sec(" + String(a) + ")=" + String(1/cosine(a)));
}if (c == "cot()"){
Serial.println("cot(" + String(a) + ")=" + String(cosine(a)/sine(a)));
}if (c == "arcsin()"){
Serial.println("arcsin(" + String(a) + ")=" + String(arcS(a)));
}if (c == "arccos()"){
Serial.println("arccos(" + String(a) + ")=" + String(PI/2-arcS(a)));
}if (c == "arctan()"){
Serial.println("arctan(" + String(a) + ")=" + String(arcT(a)));
//arcS(a/squareRoot(1 + x*x))
}if (c == "arccsc()"){
Serial.println("arccsc(" + String(a) + ")=" + String());
}if (c == "arcsec()"){
Serial.println("arcsec(" + String(a) + ")=" + String());
}if (c == "arccot()"){
Serial.println("arccot(" + String(a) + ")=" + String());
}
I tried the solutions from other similar Arduino posts, but they did not help. What do you think I should do?