Thread: Need Help with output

  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    26

    Need Help with output

    Hey guys,

    I've jut started learning c++. It's been only 2 days. I wrote a very simple program but it doesn't work properly. The problem with the program is that it doesn't output anything. Here is the code:

    Code:
    #include <iostream>
    using namespace std;
    
    const int limit = 100;
    int num = 0;
    
    int main()
    {       
        cout << "Please enter a number: ";
        cin >> num;
       
        if (num >= limit )
           cout << "HIGH ";    
        else
          cout << "LOW ";
        cout << "You are done!!"; 
        //cin >> num;  
    }
    when i run the program it prints out the first line and after the user has entered a number the program exists. I don't know why it doesn't output rest of the stuff. Is this because of my computer or complier?

    However, if i uncomment the last line which asking for another input then program outputs rest of the stuff and exits after getting another input.

    I think something wrong with my complier. I'm using Dev-C++ v 4.9.9.2. Everytime when i run it, it gives me following message and i don't know how to fix it:

    "There doesn't seem to be GNU Make File in PATH or in Dev-C++'s Bin path. Please make sure that you have the GNU Make and adjust Bin setting or system PATH environment variable and that make setting in Complier Option contains correct filename, otherwise you will not be able to compile anything,"

    Also, could someone please tell me how to output something on new or next line? Because in java i know we can use println to print anything on new line.

    Please someone help me? I would really apperciate!! Thanks in advance.

  2. #2
    Banned
    Join Date
    Jun 2005
    Posts
    594
    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {       
        const int limit = 100;
        int num = 0;
        cout << "Please enter a number: ";
        cin >> num;
        cin.ignore();
        if (num >= limit )
        {      
               cout << "HIGH ";    
        }
        else
        {
               cout << "LOW ";
        }
    
        cout << "You are done!!"; 
        cin.get();  
    }
    Even for small code brackets are nice, and im not sure
    if your describing your problem accuratly,
    try this code and see if it get your results.
    Last edited by ILoveVectors; 07-06-2005 at 10:01 AM.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    To add a new line after your text, put \n inside the string:

    cout << "LOW \n";

    or use endl to end the line and flush the output (to make sure it is written to the console):

    cout << "LOW " << endl;

  4. #4
    Registered User
    Join Date
    Jul 2005
    Posts
    26
    Thanks for the reply, it didn't work though. The problem i've should be simple but somehow i can't solve it.

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {       
        const int limit = 100;
        int num = 0;
        cout << "Please enter a number: ";
        cin >> num;
        cin.ignore();
        if (num >= limit )
        {      
               cout << "HIGH ";    
        }
        else
        {
               cout << "LOW ";
        }
    
        cout << "You are done!!"; 
    
    }
    If i run the above code, the progarm exists after getting the input. It doesn't output "LOW or either "HIGH" and also it doesn't output ""You are done!!" I just want to know why is it happening because i don't see any problem with the code. Is it it because of my complier or is it because i'm not making new project properly.

    Even if i run the "Hello World" program: The ".exe" file closes itself without outputing "Hello World". or Maybe it does but i can't see it because the ".exe" file closes itself very fast. Please someone help me. Thanks

  5. #5
    Registered User
    Join Date
    Jul 2005
    Posts
    26
    Thanks daved I got that but would you mind helping me to fix my other major problem?

  6. #6
    Registered User
    Join Date
    Jul 2005
    Posts
    26
    Never mind guys. I found the problem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. code output...
    By roaan in forum C Programming
    Replies: 6
    Last Post: 07-03-2009, 02:22 AM
  2. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  3. Replies: 4
    Last Post: 11-30-2005, 04:44 PM
  4. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 05:10 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM