C++ c+中的If语句+;双打 #包括 #包括 #包括 #包括 使用名称空间std; int main() { int x,y,z; coutx; 如果(x100); { cout

C++ c+中的If语句+;双打 #包括 #包括 #包括 #包括 使用名称空间std; int main() { int x,y,z; coutx; 如果(x100); { cout,c++,C++,有一个错误: #include <iostream> #include <windows.h> #include <cstdlib> #include <stdlib.h> using namespace std; int main() { int x,y,z; cout<<"welcome to guessing game\nplayer one pick your number: "; cin>>x; if

有一个错误:

#include <iostream>
#include <windows.h>
#include <cstdlib>
#include <stdlib.h>

using namespace std;

int main()
{
    int x,y,z;
cout<<"welcome to guessing game\nplayer one pick your number: ";
cin>>x;
if (x < 0)(x > 100);
{
    cout<<"out of number range";
}
Sleep(2000);
system("cls");
cout<<"ok player 2 pick the guess";
cin>>y;
if (x == y){
      cout<<"congrats you got it right";
           }
            else{
            if (x < y){
            cout<<"Go lower";}
            else {
            if (x > y){
            cout<<"higher";}}
            }
system("pause>nul");
return 0;
}
if(x<0)(x>100);
{
试试这个:

if (x < 0 || x > 100)
{
    cout<<"out of number range";
}
/*
如果(x<0)(x>100);
{
你能写吗

/*
if (x < 0)(x > 100);
{
    cout<<"out of number range";
}
*/

if (x < 0 || x > 100)
{
    cout<<"out of number range";
}
if(x<0)(x>100);
{

cout除了写
if(x<0 | | x>100)
(并去掉分号)之外,你应该小心比较浮点上的相等。如果(x==y){
检查你的代码,我会用红色标记你的行
if(x==y){


请参见

有几个值得注意的语法错误:

if ((x < 0) || (x > 100))
{
    cout<<"out of number range";
}

没有其他人真正回答你的第二个问题:如何循环,给你:

if ((x < 0) || (x > 100))
{
    cout << "out of number range" << endl;
}
intx;
cout x;
}而(x<0 | | x>100);

将对象放入while(true)循环
if(x100);
相当于
if(x100);}
。下面的复合语句与
if
无关。这里的每个人都解释了if不能按预期工作的原因。我将回答有关循环的部分。你不想回到程序的开头,你只想回到再次询问数字。使用
边做边
循环(见下文)@阿贝伦基,你确定吗?@MarkRansom:哇,我真的很惊讶它能编译。它看起来太错了。注意,前面的评论被删除了。更好(只是吹毛求疵):
if(x<0或x>100)你认为,也许,每个人都知道C++、C++、爪哇、C++等都知道什么是克里斯。不幸的是,<代码>或只是让人们认为它是一些非标准的扩展或什么东西。否则。没问题,去吧,伙计!:)我不认为他们打算返回0,否则第二个玩家永远不会有机会猜测,更不用说第一个玩家在不重新启动整个程序的情况下再次正确猜测了。我试图一次处理两个问题,而不是四个;-)我宁愿对代码大惊小怪除了额外的括号外,TBH.endl将缓冲区刷新为真的吗?
x
y
int
尽管有标题,这里没有浮点。@PeteBecker,我想标题是指同时做两个测试。@sickist然后通过投票并接受答案感谢他。
if ((x < 0) || (x > 100))
{
    cout<<"out of number range";
}
    if (x < 0)(x > 100);
{
    cout<<"out of number range";
}
if ((x < 0) || (x > 100))
{
    cout << "out of number range" << endl;
}
int x;
cout << "Welcome to the guessing game\n";
do {
    cout << "Please enter a number from 0 to 100: ";
    cin >> x;
} while (x < 0 || x > 100);