why it dont cout??

This is a discussion on why it dont cout?? within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> #define YES 1 #define NO 0 using namespace std; int main() { int x=YES; int y; if ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    70

    Question why it dont cout??

    Code:
    #include <iostream>
    #define YES 1
    #define NO 0
    
    using namespace std;
    
    int main()
    {
        int x=YES;
        int y;
        if (x==YES){
                    cout<<"goed geantwoord";
                    cin>>y;
                    if(y==5){
                    x==NO;
                    }
                    }
        if (x==NO){
                   cout<<"x=no";
                   }
                   return 0;
                   }
    why isnt't it couting "x=no"????
    ps: it is couting "goed geantwoord"


    thnx in advance

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,303
    Probably because you are comparing x to NO instead of assigning NO to x... and possibly also because 5 is not entered.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,851
    > x==NO;
    Because this is a useless comparison, rather than a meaningful assignment.
    Use = here.

    $ g++ -W -Wall foo.cpp
    foo.cpp: In function `int main()':
    foo.cpp:15: warning: statement has no effect
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    70
    No==x dont work
    and the rare thing is it is printing the first thing:s
    i give it some other trie

  5. #5
    Registered User
    Join Date
    Jan 2006
    Location
    Latvia
    Posts
    102
    Quote Originally Posted by Salem
    Use = here.
    It means you have to write
    Code:
    x=NO;

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    70
    btw this isnt working too
    Code:
    #include <iostream>
    
    
    using namespace std;
    
    int main()
    {
        
        int x;
         
        cout<<"goed geantwoord";
                    x=false;
                    
        if (x=false){
                   cout<<"x=no";
                   main();
                   }
                   cin.get();               
                   }

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    70
    Quote Originally Posted by Overlord
    It means you have to write
    Code:
    x=NO;
    not working

  8. #8
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by hallo007
    btw this isnt working too
    Code:
    #include <iostream>
    
    
    using namespace std;
    
    int main()
    {
        
        int x;
         
        cout<<"goed geantwoord";
                    x=false;
                    
        if (x=false){
                   cout<<"x=no";
                   main();
                   }
                   cin.get();               
                   }
    Code:
        if (x=false){
    And what does that line?

    BTW, your indentation is HORRIBLE.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,851
    > if (x=false)
    I didn't say do a global substitute of == to =

    Also, use a loop rather than calling main() recursively (which is illegal in C++)

    And echo maxorator on the code formatting.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    Registered User
    Join Date
    Sep 2006
    Posts
    70
    Quote Originally Posted by maxorator
    Code:
        if (x=false){
    And what does that line?

    BTW, your indentation is HORRIBLE.
    if i think what identitation means , (i dont know it sure)

    then you are right , i know it ,but when i change in 1minute much things and tried things it becum like this

  11. #11
    Registered User
    Join Date
    Dec 2005
    Posts
    43
    Indentation means proper alignment and spacing, as so:

    Code:
    #include <iostream>
    using namespace std;
    
    int main ()
    {
            bool x;
    
    	while ( true )
    	{
    		cout << "goed geantwoord";
    		x = false;
    	                
    		if ( x == false )
    			cout << "x=no";
    
    		cin.get();
    	}
    
    	return 0;
    }
    Although I really don't see any use for an unending program.

  12. #12
    Registered User
    Join Date
    Sep 2006
    Posts
    70
    it's for learning

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. class methods to cout stream
    By shintaro in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2008, 07:27 PM
  2. cout vs std::cout
    By none in forum C++ Programming
    Replies: 10
    Last Post: 07-27-2004, 12:20 AM
  3. changing cout output
    By Yohumbus in forum C++ Programming
    Replies: 1
    Last Post: 10-23-2002, 05:09 AM
  4. Redirecting cout stream
    By Arrow Mk84 in forum C++ Programming
    Replies: 1
    Last Post: 10-08-2002, 05:17 PM
  5. printf vs cout
    By RyeDunn in forum C++ Programming
    Replies: 5
    Last Post: 07-09-2002, 05:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21