I am working on a trigonometric functions calculator. The user would choose a function for example sin() then input a constant for example 1, then a lower boundary and an upper boundary.
The calculator should then give all values of theta between the lower boundary and the upper boundary that would give the constant when input into the sine function.
For some reason, however, not all the theta values would be printed out and sometimes, especially with the tan function, no values of theta would be printed out.
For example, when I choose the tan function and input the constant as 1, then choose a lower boundary of 0 and an upper boundary of 1000. No theta values are printed out.
I can't find the error in my program. please help me.
#include <iostream>
#include <string>
#define _USE_MATH_DEFINES
#include <cmath>
int operation; //This is the variable to store the number of the trig. function the user choose
double constant;
double lower_boundary;
double upper_boundary;
double a; //This variable is for holding the converted degrees to radians
//This is the function for getting the information needed to start giving out the possible theta values
void get_info(){
std::cout<<"Insert the value of the constant: ";
std::cin>>constant;
std::cout<<"Insert the value of the lower boundary in degrees\n( this is from where you will start getting possible values of theta ): ";
std::cin>>lower_boundary;
std::cout<<"Insert the value of the upper boundary in degrees: ";
std::cin>>upper_boundary;
std::cout<<"\nHere are your possible values for theta :\n";
}
void decide (){
std::cout<<"\nInsert the number of the trigonometric function you want:\n";
std::cout<<"1. Sin()\n";
std::cout<<"2. Cos()\n";
std::cout<<"3. Tan()\n";
std::cin>>operation;
if (operation==1){
get_info();
for (double i = lower_boundary; i<=upper_boundary; i++)
{ a = i*(M_PI/180);
if (sin(a)==constant){std::cout<<i<<"\n";}
}
}
else if (operation==2){
get_info();
for (double i = lower_boundary; i<=upper_boundary; i++)
{ a = i*(M_PI/180);
if (cos(a)==constant){std::cout<<i<<"\n";}
}
}
else if (operation==3){
get_info();
for (double i = lower_boundary; i<=upper_boundary; i++)
{ a = i*(M_PI/180);
if (tan(a)==constant){std::cout<<i<<"\n";}
}
}
else {std::cout<<"INVALID INPUT ! Please enter the number of an existing operation.\n";}
}
int main() {
std::cout<<"----------------------------------------------------------------------------\n";
std::cout<<"TRIGONOMETRIC EQUATIONS CALCULATOR\n";
std::cout<<"----------------------------------------------------------------------------\n\n";
while (true){decide();}
}