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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:52:22+00:00 2026-06-02T08:52:22+00:00

Not very good at debugging yet but I’m getting a few errors. A few

  • 0

Not very good at debugging yet but I’m getting a few errors. A few expected ‘(‘ ‘)’ and ‘;’
Also ‘else’ without a previous ‘if’, no match for ‘operator>>’ in cout

I know this is easy, but still trying to get my foot in the door. Thanks 🙂

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

int main()   // guess number game
{
    int x;
    cout >> "Please enter a number\n";
    getline(cin x);
    int y = rand();

    while x != y
    {

        if x < y;
           cout >> "Go higher";
        else;
           cout >> "Go lower";
    }


}
  • 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-02T08:52:24+00:00Added an answer on June 2, 2026 at 8:52 am
    cout >> "Please enter a number\n";
    

    This is wrong, std::ostreams only provide the operator<< to insert formatted data. Use cout << "Please enter a number\n"; instead.

    getline(cin x);
    

    First, you’re missing a ,, since getline needs two or three arguments. But since x is an integer and not a std::string it is still wrong. Think about it – can you store a text line inside of an integer? Use cin >> x instead.

    int y = rand();
    

    While this doesn’t seem wrong there’s a logical error. rand() is a pseudo random number generator. It uses a seed as start value and some kind of algorithm (a*m + b). Thus you have to specify a start value, also called seed. You can specify this by using srand(). The same seed will result in the same order of numbers, so use something like srand(time(0)).

    while x != y
    if x < y;
    

    Use parenthesis. And drop the additional ;. A stray semicolon ; in your program resembles the empty expression.

    EDIT: Working code:

    #include <iostream>
    #include <cstdlib>
    #include <ctime>
    
    int main(){
        int x;
        int y;
        srand(time(0));
        y = rand();
        std::cout << "Please enter a number: ";
        do{
            if(std::cin >> x){
                if(x < y)
                    std::cout << "Go higher: ";
                if(x > y)
                    std::cout << "Go lower: ";    
            }
            else{
                // If the extraction fails, `std::cin` will evaluate to false
                std::cout << "That wasn't a number, try again: ";
                std::cin.clear(); // Clear the fail bits
            }
        }while(x != y);
        std::cout << "Congratulations, you guessed my number :)";
    
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not very good with Regex but I am learning. I would like
I'm not very good at regex but maybe there's a simple way to achieve
Hi I have some experience with programming but I'm not very good with pointers.
I'm not very good with regular expressions but in Textmate, I'm trying to clear
I'm still not very good with data structures, but I have this homework assignment
I'm not very good at C, and I always get stuck on simple string
I'm not very good in SQL and HQL... I have two domains: class Hotel
I'm not very good at PHP and would like to have a PHP function
I'm not very good with Django's form . Here is Order from models.py class
I'm not familiar at all with JQuery and I'm not very good with CSS,

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.