Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14
Code: #include <iostream> int main() { int number1; int number2; int sum; std::cout << "Enter first integer: "; std::cin >> number1; std::cout << "Enter second integer: "; std::cin >> number2; ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie
    Join Date
    May 2009
    Location
    Kitchener, Ontario, Canada
    Posts
    206

    noobie C++ Programmer


    Code:
    #include <iostream>
    
    
    int main()
    {
    
    	int number1;
         	int number2;
    	int sum;
    	
    	std::cout << "Enter first integer: ";
    	std::cin >> number1;
    		
    	std::cout << "Enter second integer: ";
    	std::cin >> number2;
    
    	sum = number1 + number2;
    
    	std::cout << "Sum is " << sum << std::end1;
    	
    	return 0;
    
    }
    im going by the book and im having some issues here it wont compile successfully the error is:
    Code:
    [Donald@localhost ~]$ cd Desktop/C++
    [Donald@localhost C++]$ make addition
    make: *** No rule to make target `addition'.  Stop.

  2. #2
    Just Joined!
    Join Date
    Feb 2009
    Location
    Southport, England
    Posts
    31
    It's working for me. A bit silly, but are you sure you're in the right directory, and the file is called "addition.cpp"?

    By the way, you meant to write "endl" not "end1".

  3. #3
    Linux Engineer rcgreen's Avatar
    Join Date
    May 2006
    Location
    the hills
    Posts
    1,134
    Yes, works for me too.

    Code:
    rcgreen@blue:~$ make addition
    g++     addition.cpp   -o addition
    rcgreen@blue:~$ ./addition
    Enter first integer: 2
    Enter second integer: 5
    Sum is 7
    rcgreen@blue:~$

  4. #4
    Linux Newbie
    Join Date
    May 2009
    Location
    Kitchener, Ontario, Canada
    Posts
    206
    something is wrong with my compiler i think

  5. #5
    Just Joined!
    Join Date
    Sep 2010
    Posts
    3
    Quote Originally Posted by donaldfarkas View Post
    Code:
    [Donald@localhost ~]$ cd Desktop/C++
    [Donald@localhost C++]$ make addition
    make: *** No rule to make target `addition'.  Stop.
    Do you have a Makefile in the directory?

    Because "make" uses a Makefile to give it rules on how to compile source code, its not a compiler itself.

    "g++ (filename here) -o (desired filename)"
    Should compile the file(assuming there aren't errors).

    Good luck with your problem, anyway.

  6. #6
    Linux Newbie
    Join Date
    May 2009
    Location
    Kitchener, Ontario, Canada
    Posts
    206
    why do i need a makefile? its just a half a page very simple program? how come i didnt need to use a makefile with the other simple progs i created?

    if i need to use a makefile how do i make one?

  7. #7
    Just Joined!
    Join Date
    Sep 2010
    Posts
    3
    Quote Originally Posted by donaldfarkas View Post
    why do i need a makefile? its just a half a page very simple program? how come i didnt need to use a makefile with the other simple progs i created?

    if i need to use a makefile how do i make one?
    You don't need a makefile, but I assumed since you were typing 'make addition' that you might have had one or needed one for some reason, sorry for the confusion.

    But if you just want to compile the source code you can type 'g++ (filename.cpp) -o (output filename)' and it will be compiled.

  8. #8
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,517
    Actually, to build a single file into an executable, you can use make without a make file. A couple of points:

    1. On your output, since you don't output an endl until the end, you need to flush the stream, as in: std:cout << "Enter first integer: " << std::flush;
    2. The name of the file needs to be addition.cpp or addition.cc or addition.cxx in order for make to find it as a C++ source file.
    3. You can leave off the std:: cruft if you add to your file after "#include <iostream>" the directive: using namespace std;

    Anyway, this is not a compiler problem, but the fact that either you are not running make in the same directory as your file, or you have not named your file as shown above.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  9. #9
    Linux Newbie
    Join Date
    May 2009
    Location
    Kitchener, Ontario, Canada
    Posts
    206
    Donald@localhost ~]$ cd Desktop/C++
    [Donald@localhost C++]$ ls
    addition.cpp printingLineofText
    [Donald@localhost C++]$ g++ addition.cpp -o addition
    g++: addition.cpp: No such file or directory
    g++: no input files
    [Donald@localhost C++]$ ^C
    [Donald@localhost C++]$

    so above paste shows that i have navigated to the right directory and showing that the file is thereand then i try to compile and shows no such file

  10. #10
    Linux Newbie
    Join Date
    May 2009
    Location
    Kitchener, Ontario, Canada
    Posts
    206
    OH MY GOD i had a space in the file name beginning of a and did not see it

    thx for everyone taking their time and helping out

Page 1 of 2 1 2 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •