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 9158655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:17:59+00:00 2026-06-17T13:17:59+00:00

SO i have this code: #include <iostream> #include <cstdlib> using namespace std; int main()

  • 0

SO i have this code:

#include <iostream>
#include <cstdlib>
using namespace std;

int main()
{

    int x;
    x=rand();
    int guess;
    do{
        cout<<"Enter your guess:";
        cin>>guess;
        if(guess==x)cout<<"You got it ! ;)\n";
        else {
            cout<<"Wrong(";
            if (guess<x) cout<<"too small)\n";
            else cout<<"too big)\n";
        }

    } while (guess != x);

    return 0;
}

question: After compiling and running this program, i enter “999999999999” and it keeps repeating the “too big”. why is this so?

additional info: when i set the value of x to constant 10, and i entered 11, i notice it only repeats “too big” once. is there something i am not aware of? or is the code flawed?

many thanks 🙂

  • 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-17T13:18:00+00:00Added an answer on June 17, 2026 at 1:18 pm

    If you look at data types, you will see that an int can only hold up to 2,147,483,6471. When you try and input a larger number than what your data type can hold than std::cout fails and it then tries and process it again in the next loop and that also fails and it sends you in an infinite loop.

    You can fix your issue by using a bigger data type.


    1 – The size of int depends on your machine, please check http://en.cppreference.com/w/cpp/language/types for the list of ranges that an int can hold

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this simple code: #include <iostream> #include <fstream> using namespace std; int main(void)
I have this code #include <iostream> using namespace std; class Test{ public: int a;
I've try to compile this code: #include <iostream> #include <cstdlib> using namespace std; #define
I have the following code: #include <cstdlib> #include <iostream> #include <stdlib.h> using namespace std;
I have this code: #define _WIN32_WINNT 0x0500 #include <cstdlib> #include <iostream> #include <windows.h> using
I have this code: #define _WIN32_WINNT 0x0500 #include <cstdlib> #include <iostream> #include <windows.h> using
I have this code: #include <iostream> #include <functional> struct A { int operator()(int i)
I have this code: #include <stdio.h> #include <openssl/sha.h> #include <openssl/ssl.h> int main(){ printf(OpenSSL version:
I have this code which does the trick: #include <stdio.h> int main() { int
I have a code like this below in /root_project/main.cpp : #include theoraplayer/TheoraVideoClip.h unsigned int

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.