Thread: Can someone tell me why I get the "cannot build" message when I run this.

  1. #1
    Registered User
    Join Date
    Jan 2015
    Posts
    30

    Can someone tell me why I get the "cannot build" message when I run this.

    Correction: "has not been built yet". And yes, I have reinstalled.

    Very annoying.
    Code:
    #include <iostream>
    #include <ctime> 
    #include <cstdlib>
    using namespace std;
    
    int main()
    {
    srand(time(0));
          cout << 1+rand()%100; 
    }
    This does not work either.

    Code:
    #include <iostream>
    using namespace std;
    
    
    int x=10;
    
    
    int main()
    {
    int x=1;
            cout << x;
    }
    Last edited by Aenn; 01-17-2015 at 08:04 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    The error message comes from your IDE, not your code.

    You need to tell us what your code environment looks like.
    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.

  3. #3
    Registered User
    Join Date
    Jan 2015
    Posts
    30
    Quote Originally Posted by Salem View Post
    The error message comes from your IDE, not your code.

    You need to tell us what your code environment looks like.
    Do you mean the feedback from my log?

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    He means you need to tell us what IDE and compiler you are using.

    Yes, feedback from a log would also help.

  5. #5
    Registered User
    Join Date
    Jan 2015
    Posts
    30
    Quote Originally Posted by whiteflags View Post
    He means you need to tell us what IDE and compiler you are using.

    Yes, feedback from a log would also help.
    My compiler and IDE are both included in Code::Blocks.

  6. #6
    Registered User
    Join Date
    Jan 2015
    Posts
    30
    This one is having the same issue.

    Code:
    #include <iostream> 
    using namespace std;
    
    
    void pass_by_value(int a);
    void pass_by_reference(int *a);
    
    
    int main()
    {
    int x=13;
    int y=13;
    pass_by_value(x);
    pass_by_reference(&y);
        cout << "x is now set to " << x << endl;
        cout << "y is now set to " << y << endl;
    }
    
    
    void pass_by_value(int a)
    {
    a=99;
    }
    
    
    void pass_by_reference(int *a)
    {
    *a=66;
    }

  7. #7
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    Quote Originally Posted by Aenn View Post
    This one is having the same issue.

    Code:
    #include <iostream> 
    using namespace std;
    
    
    void pass_by_value(int a);
    void pass_by_reference(int *a);
    
    
    int main()
    {
    int x=13;
    int y=13;
    pass_by_value(x);
    pass_by_reference(&y);
        cout << "x is now set to " << x << endl;
        cout << "y is now set to " << y << endl;
    }
    
    
    void pass_by_value(int a)
    {
    a=99;
    }
    
    
    void pass_by_reference(int *a)
    {
    *a=66;
    }
    Are you able to compile the project template that comes with the project ? I mean, when you select 'console project' what comes up is a simple 'hello world' template, does it compile ?

  8. #8
    Registered User
    Join Date
    Jan 2015
    Posts
    30
    Quote Originally Posted by Aslaville View Post
    Are you able to compile the project template that comes with the project ? I mean, when you select 'console project' what comes up is a simple 'hello world' template, does it compile ?
    I have run many many other programs that have run just fine. So far it has just been these 3 with the problem.

  9. #9
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    Quote Originally Posted by Aenn View Post
    I have run many many other programs that have run just fine. So far it has just been these 3 with the problem.
    You didn't really answer me. Does the 'hello world' template project compile ?

    You may want to try cleaning the project. From the 'build' menu you get the 'clean' submenu.

  10. #10
    Registered User
    Join Date
    Jan 2015
    Posts
    30
    Quote Originally Posted by Aslaville View Post
    You didn't really answer me. Does the 'hello world' template project compile ?

    You may want to try cleaning the project. From the 'build' menu you get the 'clean' submenu.
    I selected Build-->Compile current file and it gave me no problems. (No warnings, errors, or anything like that in the log)
    I also selected Build-->Clean and it also gave me no problems. (It just said "Done" at the bottom)

  11. #11
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    Quote Originally Posted by Aenn View Post
    I selected Build-->Compile current file and it gave me no problems. (No warnings, errors, or anything like that in the log)
    I also selected Build-->Clean and it also gave me no problems. (It just said "Done" at the bottom)
    In that case, you might need to redefine your problem. I mean state what is your current problem in a clear manner

  12. #12
    Registered User
    Join Date
    Jan 2015
    Posts
    30
    1.) I write my source code.





    Can someone tell me why I get the &quot;cannot build&quot; message when I run this.-desktop-1-18-2015-12-40-25-am-714-jpg





    2.) I build and run the source code.





    Can someone tell me why I get the &quot;cannot build&quot; message when I run this.-desktop-1-18-2015-12-40-29-am-724-jpg




    3a) If I select "Yes" it closes and that's the end of it.





    Can someone tell me why I get the &quot;cannot build&quot; message when I run this.-desktop-1-18-2015-12-40-25-am-714-jpg





    3b) If I select "No" it opens up this cmd prompt.





    Can someone tell me why I get the &quot;cannot build&quot; message when I run this.-capture-jpg

  13. #13
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    Wait, Are you creating a project or are you just loading the file ? Seems like the latter.

    File -> new -> project choose console application, get rid of the contents of 'main.c' and paste your code there.
    Last edited by Aslaville; 01-17-2015 at 11:57 PM.

  14. #14
    Registered User
    Join Date
    Jan 2015
    Posts
    30
    Quote Originally Posted by Aslaville View Post
    Wait, Are you creating a project or are you just loading the file ? Seems like the latter.

    File -> new -> project choose console application, get rid of the contents of 'main.c' and paste your code there.
    Same error.

  15. #15
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    Quote Originally Posted by Aenn View Post
    Same error.
    Well, Not much sense from this one.

    Did you see the 'hello world' template ? Did it compile ?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 12-08-2014, 08:12 PM
  2. "Game Over" program build fail?
    By mdbay in forum C++ Programming
    Replies: 4
    Last Post: 01-20-2013, 01:52 PM
  3. Replies: 1
    Last Post: 07-26-2010, 10:21 AM
  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