Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8877493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:28:53+00:00 2026-06-14T19:28:53+00:00

Yeah. So, I’m trying to make a code for a guessing game. In this

  • 0

Yeah. So, I’m trying to make a code for a guessing game. In this game, there’s a hard mode. In hard mode, you have 15 guesses, and have to guess between 1 and 500. But my problem is this:
I’m trying to have hard mode save & display your wins/losses, but when it outputs the contents of wins.txt it outputs something like this:

Wins: 0x7fffee26df78
Losses: 0x7fffee26e178

It’s really confusing me. Here’s the part of the code I have for that:

ifstream losses_var("losses.txt");
ifstream wins_var("wins.txt");
losses_var>> loss;
wins_var>> win;
wins_var.close();
losses_var.close();

Then it gets called with:

cout<<"Wins: "<< wins <<"\nLosses: "<< losses <<"\n"

If you would like to see the full source code, it’s here: http://pastebin.com/gPT37uBJ

My second problem:
Hard mode won’t display when you win. That’s pretty much the whole problem. In my code, the loop for asking users for input uses
while (guess != randNum)
So at the end bracket I have what I want the code to display when a user wins, but it just doesn’t run. It just stops. I would like it if someone could help me with this. The line that has the bug is line 97 through 105. Again, source code is here: http://pastebin.com/gPT37uBJ

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:28:54+00:00Added an answer on June 14, 2026 at 7:28 pm

    Others have already answered the output problem (win vs. wins). The other problem is probably in your logic of while loop nesting. The outer loop (while (guess != randNum)) starts, but its body contains the entire inner loop (while (guesses_left != 0)). This means that the outer condition is not checked again until the inner loop terminates, which means you’ve run out of guesses. Also note that if you guess correctly, inner loop will never terminate. You probably want something like this:

    while (guesses_left > 0) {
      // input user's guess
      if (guess < randNum) {
        // process it
      } else if (guess > randNum) {
        // process it
      } else {
        // it's equal, user won
        // do what's necessary for a win
        return 0;
      }
    }
    // ran out of guesses
    // do what's necessary for a loss
    return 0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some troubles with this small JavaScript code: var text=Z Test Yeah !
So yeah, like I said, I've spent a few hours trying to fix this
This shows what I have and want: So yeah as you can see I
Yeah I know it's hard to believe - bug in .NET? But run this
Yeah, there's this cool myLabel.adjustsFontSizeToFitWidth = YES; property. But as soon as the label
yeah! i have written the code inside viewDidLoad method but work properly!!! my prolblem
In the python docs ( yeah, I have this thing with the docs )
Yeah some people on the web have the same problem.. but there was no
So yeah, I'm just trying to see if there is a more elegant way
Yeah, I was wondering if there's a way to make a link the size

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.