Abl*_*rab 0 c++ variables integer
这可能很容易理解,但出于某种原因,我无法在任何地方找到解决方案.也许我不是在寻找合适的东西.也许它是在一些我没有看过的初学者教程中.
无论如何,我想知道如何在C++中检索整数变量的值?我知道你可以使用cin.getline()字符串变量,但是当我尝试使用整数变量时,我收到了一条错误消息(理所当然,我知道这是错误的,但我正在寻找解决方案).
我的项目是Win32控制台应用程序.我要做的是要求用户输入存储在变量中的数字n.然后我拿它的值n并用它执行各种数学函数.在我的头文件,我有string,windows,iostream,stdio,math,和fstream.我需要添加另一个库吗?
编辑:
cout << "TEST SINE";
cout << "\nPlease enter a number.\n\n";
cin >> n;
break;
这是我正在尝试使用的代码.这就是我需要做的吗?如果是这样,我如何合并变量,以便我可以使用sin,cos和tan来测试它?
再次,谢谢你提前.
这有什么问题?
cin>>n;
对于数学函数,float或double是更好的选择.
int main()
{
   double number;
   double result;
   cout<<"Enter a number:"<<endl;
   cin>>number;
   result = sin (number);  //if you consider number is in radians
   //result = sin(number*3.14159265/180.0) //if you consider number is in degrees    
   cout<<result;
   return 0;
}