在这个程序中,我被迫为3个trig函数“sind,cosd,tand”调用函数,我必须调用它们到主程序。我对如何让它们发挥作用毫无头绪。我还必须以度为单位输入值。我也不知道'while'语句应该是什么。非常感谢任何提示。
#include <iostream>
#include <cmath>
#include <iomanip>
double sind();
int main(void)
{
double s, c, t;
char select;
std::cout << "Trigonometric functions in degrees." << std::endl << std::endl;
std::cout << "Please select a funcion to be performed : " << std::endl << std::endl;
do
{
std::cout << "S/s: sin, " << "C/c: cos, " << "T/t: tan, " << "E/e: Exit" << std::endl;
std::cout << "please enter your selection. \n";
std::cin >> select;
switch (select)
{
case 'S' : case 's':
std::cout << "Please enter a value in degrees : ";
std::cin >> s;
std::cout << "sin(" << s << " degrees" << ")" << "=" << sind << std::endl;
break;
case 'C' : case 'c':
std::cout << "Please enter a value in degrees : ";
std::cin >> c;
std::cout << "cos(cos) : " << "cosd "<< std::endl;
break;
case 'T' : case 't':
std::cout << "Please enter a value in degrees : ";
std::cin >> t;
std::cout << "tan(tan) : " << "tand" << std::endl;
break;
case 'E' : case 'e' :
std::cout << "Program has terminated. Goodbye." << std::endl;
break;
default:
std::cout << "You have entered an invalid code. Please try again." << std::endl;
}
} while (select != 'e');
}
答案 0 :(得分:-1)
正如@FrançoisAndrieux所说,你应该真正了解函数在C ++中是如何工作的。 以下是您的具体问题的一些帮助: 要以度为单位计算角度的正弦值,必须先将其转换为弧度:
double s_rad = s / 180 * PI;
您必须在include语句和主函数的开头之间定义Pi
#define PI 3.14159265
然后,您可以通过将其写入函数名称后面的括号中来将此值传递给函数:
double result = sin ( s_rad );
或直接
double result = sin (s / 180 * PI);