Pergunta

I have my program here.

#include <iostream>
#include <string>
using namespace std;
int main()
{
string input;
cout << "say yes or no" << endl;
cin >> input;
if(input == Yes)
{
    cout << "test" << endl;
}
else if(input == No)
{
    cout << "test123" << endl;
}
system("pause");
}

It says that Yes and No are undefined? Please help I am new to c++

Foi útil?

Solução

You should use doubleQuotes for string "Yes" "No"

Outras dicas

First, Yes and No without double quote are read as variable by the compilator, and you didn't declare any Yes or No variable.

Second, I don't think you can compare String like that in C++ : you have to use compare ( http://www.cplusplus.com/reference/string/string/compare/ ) so the prog will be :

#include <iostream>
#include <string>
using namespace std;
int main()
{
  string input;
  cout << "say yes or no" << endl;
  cin >> input;
  if(input.compare("Yes"))
  {
    cout << "test" << endl;
  }
  else if(input.compare("No"))
  {
    cout << "test123" << endl;
  }
  system("pause");
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top