Find the answer to your Linux question:
Results 1 to 7 of 7
Code: //Author: Donald Farkas //Created: Sep/4/2010 #include <iostream> using std::cout; using std::cin; using std::endl; int main() { int houryWage, hoursWeek, yearSalary; cout << "Please enter hourly wage: " << endl; ...
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

    Created my first little program in C++ that im happy about


    Code:
    //Author: Donald Farkas
    //Created: Sep/4/2010
    #include <iostream>
    using std::cout;
    using std::cin;
    using std::endl;
    
    int main()
    {
    	int houryWage, hoursWeek, yearSalary;
    	
    	cout << "Please enter hourly wage: " << endl;
    	cin >> houryWage;
    	
    	cout << "Please enter total amount hours per week:" << endl;
    	cin >> hoursWeek;
    
    	yearSalary = houryWage * hoursWeek * 52;
    
    	cout << "Your yearly salary is " << yearSalary << " before taxes." << endl;
    
    	return 0;
    
    }

    I know its very simple but im proud i did not use any help with anything at all

  2. #2
    Just Joined! gnuuser's Avatar
    Join Date
    Nov 2009
    Location
    northwestern Pa, usa
    Posts
    69
    great!
    and congrats
    that the best way
    to write one and debug it is the proper procedure for any program. It is possible to write without making errors but we play it safe and check our work.

    all too often software companies have several code writers that are working on their piece of the project and the software is patched together and it sometimes doesn't get retested during each phase before release.
    therefore the reason for bug fixes and patches

  3. #3
    Just Joined!
    Join Date
    Sep 2010
    Posts
    7

    more info

    congrats

    can you please put the exact commands you used to compile this program, link this program and run this program, including any library environmental variable setups?

    i am just starting on Linux but using plain C (not C++) and using GCC compiler, so I suspect my task will be similar to yours.

    thanks

  4. #4
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    Quote Originally Posted by acid_rider View Post
    i am just starting on Linux but using plain C (not C++) and using GCC compiler, so I suspect my task will be similar to yours.
    Not quite. For C++ one needs some additional libraries for the C++ stdlib or needs to start a specific compiler.

    For your first C program, you type:
    Code:
    cc myprogam.c -o myprogram
    Debian GNU/Linux -- You know you want it.

  5. #5
    Just Joined!
    Join Date
    Sep 2010
    Posts
    7

    Mmi

    Quote Originally Posted by GNU-Fan View Post
    Not quite. For C++ one needs some additional libraries for the C++ stdlib or needs to start a specific compiler.

    For your first C program, you type:
    Code:
    cc myprogam.c -o myprogram
    more info please - what libraries/paths/env variables do I need to set? how do i link (ld?). I am using GCC C compiler and I dont even know what linker I need, I presume ld ? Alternatively can you point me to some on-line books on the topic?

    thanks

  6. #6
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    Posts
    935
    Quote Originally Posted by acid_rider View Post
    what libraries/paths/env variables do I need to set?
    None. Your distributor should have taken care of that job already.

    Quote Originally Posted by acid_rider View Post
    how do i link (ld?).
    The cc command, if called as above, automatically links the object file in order to produce an executable.

    Quote Originally Posted by acid_rider View Post
    I am using GCC C compiler and I dont even know what linker I need, I presume ld ?
    As I said, the compiler usually invokes the linker automatically for you. Unless he is told not to. If you wish to do it yourself, ld is the program.

    Quote Originally Posted by acid_rider View Post
    Alternatively can you point me to some on-line books on the topic?
    GCC online documentation - GNU Project - Free Software Foundation (FSF)
    Debian GNU/Linux -- You know you want it.

  7. #7
    Linux Newbie
    Join Date
    May 2009
    Location
    Kitchener, Ontario, Canada
    Posts
    206
    Quote Originally Posted by acid_rider View Post
    congrats

    can you please put the exact commands you used to compile this program, link this program and run this program, including any library environmental variable setups?

    i am just starting on Linux but using plain C (not C++) and using GCC compiler, so I suspect my task will be similar to yours.

    thanks
    in C++

    g++ filename.cpp -o filename

    in C

    the file extention is just .c and also im not sure if it works cause i heard iostream wont work also

Posting Permissions

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