Thread: Having trouble with a code on "if" statement

  1. #1
    Registered User
    Join Date
    Oct 2014
    Posts
    4

    Having trouble with a code on "if" statement

    Here is the code:

    Code:
    #include <windows.h>
    #include <iostream>
    using namespace std;
    void SetWindow(int Width, int Height)
        {
        _COORD coord;
        coord.X = Width;
        coord.Y = Height;
        _SMALL_RECT Rect;
        Rect.Top = 0;
        Rect.Left = 0;
        Rect.Bottom = Height - 1;
        Rect.Right = Width - 1;
        HANDLE Handle = GetStdHandle(STD_OUTPUT_HANDLE);      // Get Handle
        SetConsoleScreenBufferSize(Handle, coord);            // Set Buffer Size
        SetConsoleWindowInfo(Handle, TRUE, &Rect);            // Set Window Size
        }
    int main(void)
        {
        SetWindow(100,50);
        cout << "Hello world!" << endl << "The End is Nigh" << endl;
        int thisisanumber;
        int n;
        cout << "Please enter a Number here: ";
        cin>> thisisanumber;
        cin>> n;
        cin.ignore();
        cout<< "You entered: "<<thisisanumber <<"/"<<n;
        cin.get();
        if(cin>> n == true);
        {
            cout << "than what is the number:"<<thisisanumber;
        }
        }

    but cannot figure out this "if" statement
    any help would be greatly appreciated

    error = if(cin>> n == true);

    thnx

    Althalus

  2. #2
    Registered User
    Join Date
    Oct 2014
    Posts
    4
    sorry about messiness the auto format on the forum destroys all format I put in before

  3. #3
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    Code:
    if ( cin >> x )
    Should work

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    To explain the error, stream types (including std::istream, which std::cin is an instance of) do not supply an operator==() that permits comparing them with a bool.

    istream is actually a specialisation of a template type, and stream types also support a number of templated comparison operators. Because of this, there is a good chance that compilers will complain rather lavishly and cryptically about this error (since, to conclude there is no match, several templates need to be tried).
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  5. #5
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Code:
    if(cin>> n == true);
    Read #6 here: 8 Common Programming Mistakes - Cprogramming.com

  6. #6
    Registered User
    Join Date
    Oct 2014
    Posts
    4
    Tried this and it gave me syntax error
    ";" needed

  7. #7
    Registered User
    Join Date
    Oct 2014
    Posts
    4
    Will retry this but I think I got a syntax error "==" is not a valid parameter

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    If you get an error, show the code. That's the easiest way for us to diagnose what you've done wrong.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    Jul 2014
    Location
    Central Arizona
    Posts
    61
    I'm new to C++ but you did an input for n on line 26. But the if statement is used to make some kind of comparison, so why did you use cin<< inside the brackets at all. And Matticus is right you don't use a a semicolon after a if statement.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. question about the "fd_set *writefds" parameter in the select() statement
    By django in forum Networking/Device Communication
    Replies: 5
    Last Post: 09-09-2011, 04:16 PM
  2. An interesting code about "struct" in "union"
    By meili100 in forum C++ Programming
    Replies: 3
    Last Post: 04-08-2008, 04:37 AM
  3. Replies: 1
    Last Post: 08-06-2007, 10:09 PM
  4. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 08:25 AM
  5. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 07:59 AM

Tags for this Thread