C++ 数当てゲーム

#include <iostream>
#include <random>

int main() {
    // 1. 初期化処理(1〜100のランダムな正解を生成)
    std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_int_distribution<> dist(1, 100);

    int target = dist(gen);
    int guess = 0;
    int attempts = 0;
    bool isGameOver = false;

    std::cout << "=== 数当てゲーム (1〜100) ===" << std::endl;
    std::cout << "コンピュータが思い浮かべた数字を当ててください!" << std::endl;

    // 2. ゲームループ(クリアするまで繰り返す)
    while (!isGameOver) {
        std::cout << "\n数字を入力 > ";

        // 数字以外の不正な入力に対するエラー処理
        if (!(std::cin >> guess)) {
            std::cin.clear();
            std::cin.ignore(10000, '\n');
            std::cout << "有効な数字を入力してください。" << std::endl;
            continue;
        }

        attempts++;

        // 3. 判定と結果の出力
        if (guess < target) {
            std::cout << "もっと【大きい】数字です。" << std::endl;
        }
        else if (guess > target) {
            std::cout << "もっと【小さい】数字です。" << std::endl;
        }
        else {
            std::cout << "\n正解! " << attempts << " 回目でクリアしました!" << std::endl;
            isGameOver = true; // ループ終了フラグを立てる
        }
    }

    // 4. 終了処理
    std::cout << "ゲームを終了します。お疲れ様でした!" << std::endl;
    return 0;
}

投稿者: chosuke

趣味はゲームやアニメや漫画などです

「C++ 数当てゲーム」への13件のフィードバック

  1. Quietly enjoying that I have found a new site to follow for the topic, and a look at leadspike reinforced the small pleasure of the find, the discovery of new high quality sources is one of the more durable pleasures of careful internet reading and this site has been generating that discovery pleasure at multiple points already today.

  2. Thanks for keeping things clear and to the point, that is honestly hard to find online these days, and after reading through clickprohub the message stayed consistent which makes me trust the information being shared more than I usually do on similar pages that cover this same kind of topic.

  3. is memo pezil legitimate memo pezil user reviews [url=https://recallpathh.com/memo-pezil-review/]does memo pezil work[/url] memopezil supplement memo pezil genuine reviews

  4. In the middle of an otherwise scattered day this post landed as a moment of focus, and a stop at onlinerankingstudio extended that focused feeling across more pages, content that anchors a fragmented day rather than contributing to the fragmentation is content with real centring effect and this site is providing that anchoring function for me.

  5. Профессиональное сопровождение является деликатный формат организации качественного времяпрепровождения, что даёт шанс ощущать себя спокойно в деловых ситуациях.
    Подобный вид услуг основывается на деликатности и чётких правилах безопасности, что обеспечивает условия надёжности для каждого клиента.
    Используя такой подход получается элегантно разнообразить туристическую экскурсию и сделать её по-настоящему яркой.
    индивидуалки москва телеграм

  6. Keeping a car in good shape takes effort. I prefer reading clear information about regular inspections and repair work. While searching for vehicle care tips, I came across https://www.avtorepair.xyz . It discusses different automotive issues, and it is worth a look for car owners. I enjoy learning about basic checks and common repairs.

  7. If you’re a frequent player, VIP Program perks
    can include extra casino bonuses, faster withdrawals, and
    personalised offers. I’ve used plenty of Australian online casinos,
    and honestly, PayID deposits are almost always instant.
    PayID withdrawals let Aussie players enjoy fast, transparent, and reliable access to their winnings.
    Some of the exciting crash games you’ll find include Super Beto Crash, Speed Crash, Dragon’s Crash, Big Bass Crash, and Crash X.

    Banks do apply daily limits on payments to a new PayID, typically A$1,
    000 to A$5,000 for the first 24 hours, which can affect a
    large first deposit. The casinos listed here are licensed offshore and accept Australian customers.

    References: https://forum.farsilearn.org/d/9-vip-payid-casinos-fast-deposits-fees-and-payouts

  8. Withdrawal times, however, depend on the specific casino’s policies.
    Withdrawing money from a casino using PayID in Australia typically requires using an alternative method since PayID
    is mainly for deposits. As for the best online casino PayID
    withdrawals Australia, this option is currently only available through local sports and lottery operators.
    Users who bet on resources with a local licence can expect straightforward top-ups and instant online casino PayID withdrawal Australia.

  9. After logging into your account, open the deposit section and check the casino payments
    page. After creating your membership, complete the KYC process immediately.

    First, choose one of the casinos included in the payid pokies list we prepared.

    In this section, we will explain how you can make
    an instant bank transfer within minutes in 5 easy steps. Of course, as the first and most important step, your account on an Australian online
    pokies payid site must be verified. Depositing money into a payID pokies casino account is a very simple and fast process for Aussie players.

    References: https://lecomteyachts.eu/forum/topic/payid-pokies-fast-aud-play-for-australian-slot-fans/

  10. Operated by the same NovaForge Ltd group as Pistolo, it shares the same reliable PayID infrastructure
    — our March 2026 test withdrawal completed in just 43 minutes.
    CrownPlay is built for players who want the fastest possible PayID withdrawal casino experience in Australia.
    Our test withdrawal via PayID cleared in 48 minutes — one of the
    fastest results we’ve recorded. Take advantage of safe play
    tools offered by operators, such as deposit limits,
    session timers, and account self-exclusion options. Once an operator releases your funds, PayID usually completes the transaction within minutes.

    References: https://forum.summit-wind.com/

  11. These pokies combine immersive themes with special features like wilds,
    multipliers and free spins for a more exciting experience.
    Whether you prefer classic fruit machines or high-volatility games
    with massive multipliers, these real-money pokies deliver
    thrilling gameplay and plenty of free spins opportunities.
    Cashouts above A$5,000 trigger additional VIP verification, so factor that in if
    you are playing at higher stakes. The lobby runs past 5,
    000 titles, weighted heavily toward pokies, with Pragmatic Play, Booming Games and BGaming doing most of the heavy
    lifting.

    References: https://flarum.stage.wp5.cz/

コメントを残す

メールアドレスが公開されることはありません。 ※ が付いている欄は必須項目です