寻求帮助PLZ [英] looking for help plz

查看:104
本文介绍了寻求帮助PLZ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法弄清楚为什么这不会运行。



Can't figure out why this won't run.

#include<iostream>
using namespace std;

void main ()

{

    int x;

    cout<<"Am I the best person on this earth?\n";
    cout<<"Please enter yes or no.\n";
    cin>>x;

    if (x == yes)

    {

    cout<<"You are correct, heaven welcomes you!\n";

    }

    if (x == no)

    {
        cout<<"You are incorrect, the devil will eat your soul!\n";

    }

    else

    {

        cout<<"Please answer the queston";

    }


}

推荐答案

引用:

无法弄清楚为什么这不会运行。

Can't figure out why this won't run.



甚至不编译:你正在使用未定义的符号没有(您还使用了需要字符串的整数变量)。 />


尝试:




It even don't compile: you are using undefined symbols yes and no (you are also using an integer variable where a string is required).

Try:

#include <iostream>
#include <string>
using namespace std;
 
int main ()
{
  string answer;
 
  cout << "Am I the best person on this earth?\n";
  cout << "Please enter 'yes' or 'no'.\n";
  cin >> answer;
 
  if (answer == "yes")
  {
    cout << "You are correct, heaven welcomes you!\n";
  }
  else if (answer == "no")
  {
    cout << "You are incorrect, the devil will eat your soul!\n";
  }
  else
  {
    cout << "Please answer either 'yes' or 'no'.";
  }
}


make变量:

make variables:
char yes = 'y';
char no = 'n';


试试这个

try this
int x;

cout<<"Am I the best person on this earth?\n";
cout<<"Please enter 1.yes or 0.no.\n";
cin>>x;

if (x == 1)
{

    cout<<"You are correct, heaven welcomes you!\n";

}

else if (x == 0)
{
    cout<<"You are incorrect, the devil will eat your soul!\n";

}
else
{

    cout<<"Please answer the queston";

}


这篇关于寻求帮助PLZ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆