#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语句是否起作用,无论我键入什么数字都会自动显示超出范围的数字。我也被允许像so(x 100);那样封闭条件。还如何使它返回程序的开头?
最佳答案
发生错误:
if (x < 0)(x > 100);
{
cout<<"out of number range";
}
应该:
if (x < 0 || x > 100)
{
cout<<"out of number range";
}
您还需要处理缩进;那些朝向底部的
if
/ else
语句看起来很晦涩(由于缩进,我无法真正看出来)。