#include
using std::cout;
using std::cin;
using std::endl;
int main()
{
cout << endl;
int n = 0;
double prev1 = 1.0;
double prev2 = 1.0;
double current = 0.0;
cout << "how many fib.nums to generate?";
while (!(cin>>n))
{
cin.clear();
cin.sync();
cout << "Please re-enter."<
}
cout.precision(15);
while (n > 0)
{
current = prev1 + prev2;
prev2 = prev1;
prev1 = current;
--n;
}
cout << current << "\t";
cout << "ratio=" << prev1 / prev2 << endl;
cout << endl;
cout << "Press enter to exit.";
cin.ignore();
cin.ignore();
return 0;
}
vs中输入字母会陷入死循环 另一个正常运行