fork download
  1. #include <iostream>
  2. using namespace std; // consider removing this line in serious projects
  3.  
  4. int main() {
  5. cout<<"猜一个数字";
  6. int intNum = 0;
  7. int example=42;
  8. cin >> intNum;
  9. while (intNum != example) {
  10. if (intNum > example){
  11. cout<<intNum<<"猜大了"<<endl;
  12. cin>>intNum;
  13. }
  14. if(intNum<example){
  15. cout<<intNum<<"猜小了"<<endl;
  16. cin>>intNum;
  17. }
  18. }
  19. cout<<intNum<<"猜对了";
  20. return 0;
  21. }
Success #stdin #stdout 0.01s 5280KB
stdin
1
2

42
42
stdout
猜一个数字1猜小了
2猜小了
42猜对了