错误信息:
这是什么意思?
我该如何解决?
错误C2040:'==':'int'的间接级别与'const char [2]'不同
码:
#include <iostream>
#include <cmath>
using namespace std;
int round(double number);
//Assumes number >=0.
//Returns number rounded to the nearest integer.
int main()
{
double doubleValue;
char ans;
do
{
cout << "Enter a double value: ";
cin >> doubleValue;
cout << "Rounded that number is " <<round(doubleValue)<< endl;
cout << "Again? (y/n): ";
cin >> ans;
}
//Here is the line generating the problem, while(...);
while (ans == 'y' || ans == "Y");
cout << "End of testing.\n";
return 0;
}
//Uses cmath
int round(double number)
{
return static_cast<int>(floor(number + 0.5));
}
Run Code Online (Sandbox Code Playgroud)
Tod*_*lin 10
你需要单引号char
文字.你为第一个而不是第二个正确地做了这个:
while (ans == 'y' || ans == "Y");
Run Code Online (Sandbox Code Playgroud)
这应该是:
while (ans == 'y' || ans == 'Y');
Run Code Online (Sandbox Code Playgroud)
双引号用于string(const char[]
)文字.