全部评论 3

  • 在?

    2024-08-30 来自 浙江

    0
  • 不行,笑死我了没做边界判断,导致乱输数字竟然可以变成边界?

    #include <Windows.h>
    #include <bits/stdc++.h>
    using namespace std;
    void pga() {
    system("cls");
    int a=0,b=0,l=0,r=0;
    srand(static_cast<unsigned int>(time(0)));
    cout<<"猜数字游戏!\n"<<"请输入最小值和最大值:\n";
    cin>>a>>b;
    l=min(a,b);r=max(a,b);
    int pg = 0,nc = 0,ng = rand() % r + l;
    system("cls");
    cout<<l<<"~"<<r<<"猜数字。\n";
    while (pg != ng) {
    cout << "请输入你的猜测:";
    cin >> pg;
    nc++;
    if(pg < ng && pg > l){
    cout << "太小了,范围在:"<<pg<<"~"<<r<<endl;
    l = pg ;
    }else if(pg > ng && pg < r){
    cout << "太大了,范围在:"<<l<<"~"<<pg<<endl;
    r = pg ;
    }else if(pg <= l || pg >= r){
    cout << "不要乱输入,再重申一遍,范围在:" << l << "~" << r << "\n";
    }else{
    cout << "恭喜你,猜对了!你一共猜了" << nc << "次。" << endl;
    }
    }
    }int main() {
    char pa = 'y';
    while (pa == 'y') {
    pga();
    cout << "你想再玩一次吗?(y/n): ";
    cin >> pa;
    }system("cls");
    MessageBoxA(NULL, "猜数字已运行完毕", "关闭",MB_ICONWARNING);
    }
    

    修改了一下加了下边界条件

    2024-08-19 来自 浙江

    0
  • 报错:
    未命名1 In function 'int main()':
    35 72 未命名1 [Error] expected '}' at end of input
    28 13 未命名1 [Note] to match this '{'
    C:\Users\Administrator\Desktop\未命名1.cpp In function 'int main()':
    35 72 C:\Users\Administrator\Desktop\未命名1.cpp [Error] expected '}' at end of input
    28 13 C:\Users\Administrator\Desktop\未命名1.cpp [Note] to match this '{'

    2024-08-19 来自 浙江

    0

热门讨论