Menu

Main Menu
Talk Get Daily Search

Member's Online

    User Name
    Password

    [solved](.cpp)"Hello world" in n900 (getting error) plz guide me.

    Reply
    Page 3 of 4 | Prev |   1     2   3   4   | Next
    demolition | # 21 | 2011-06-16, 13:14 | Report

    Originally Posted by SubCore View Post
    system() is evil. case in point: "pause" is a windows/dos command, and won't work here.
    It is useful in simple cases so one can actually see the console output before it vanishes. Though, didn't know "pause" wasn't possible outside windows/dos.

    These will work.

    Simple way (but might not be visible)
    Code:
    #include <iostream>		// use correct i.e. C++ library
    
    int main()			// declare f'n name & return type
    {
    	using namespace std;	// do this inside scope
    
    	cout << "hello, world";	// self-terminating string
    	cout << endl;		// output a line end
    
    	return 0;		// return an int - quit programme
    }
    If the console disappears too quickly, this version should help:
    Code:
    #include <iostream>		// use correct i.e. C++ library
    
    int main()			// declare f'n name & return type
    {
    	using namespace std;	// do this inside scope
    
    	cout << "hello, world";	// self-terminating string
    	cout << endl;		// output a line end
    
    	// get console to wait for user input...
    	cout << "Press any letter then [Enter]";
    	cout << std::endl;	// end line after user instruction
    	char ch;		// temporary variable
    	cin >> ch;		// store letter
    	cout << ch;		// do something with it
    
    	return 0;		// return an int - quit programme
    }
    Never spent so much time on the first programme! Guess making things multi-system has to start at the beginning....

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following User Says Thank You to demolition For This Useful Post:
    nicholes

     
    nicholes | # 22 | 2011-06-16, 13:16 | Report

    Originally Posted by SubCore View Post
    after it compiles without error, you have to make the resulting file (a.out is default) executable by "chmod +x a.out". this has to be done in a folder which supports this flag, MyDocs is a FAT filesystem which does NOT support it.
    copy it to /home/user f.ex., then use chmod +x.
    well there are too many programmes i have got in the thread(thanks to all of you genus guys)

    since i am very very new in coding so i want to know what to type in xterminal after this (see image)

    i have got a.out in home/ user/
    (see my first post to know what i have installed on n900 to run .cpp)
    (i myself not clear what i have done! lol)

    Edit | Forward | Quote | Quick Reply | Thanks
    Attached Images
     

    Last edited by nicholes; 2011-06-16 at 13:19.

     
    SubCore | # 23 | 2011-06-16, 13:27 | Report

    Originally Posted by nicholes View Post
    since i am very very new in coding so i want to know what to type in xterminal after this (see image)
    since you have a.out in /home/user, which is a proper linux filesystem (ext2), type
    Code:
    chmod +x a.out
    to make it executable. then you can run it by
    Code:
    ./a.out
    note the ./ at the beginning, this tells your shell to look in the current directory (which, contrary to windows systems, is NOT part of the $PATH variable).

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following 2 Users Say Thank You to SubCore For This Useful Post:
    demolition, nicholes

     
    nicholes | # 24 | 2011-06-16, 13:32 | Report

    Originally Posted by SubCore View Post
    since you have a.out in /home/user, which is a proper linux filesystem (ext2), type
    Code:
    chmod +x a.out
    to make it executable. then you can run it by
    Code:
    ./a.out
    note the ./ at the beginning, this tells your shell to look in the current directory (which, contrary to windows systems, is NOT part of the $PATH variable).
    thanks it did work for me

    hello world apeared thanks to all

    CHEERS!!!!!!!!

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following User Says Thank You to nicholes For This Useful Post:
    Captwheeto

     
    StefanL | # 25 | 2011-06-16, 13:54 | Report

    Not being a real C or C++ programmer, should the logic of the program not be something like:

    While no user input -> Hello World.


    Edit | Forward | Quote | Quick Reply | Thanks

     
    demolition | # 26 | 2011-06-16, 14:44 | Report

    Originally Posted by StefanL View Post
    Not being a real C or C++ programmer, should the logic of the program not be something like:

    While no user input -> Hello World.

    No. The sole purpose of this programme is to produce an output i.e. "hello, world". Nothing else. The only user input should be to run the programme, that's it. The slight glitch can be that the console disappears so fast the output cannot be read hence my alternate version, which does require user input.

    The entry point of a C++ programme is main(), or pseudo-name thereof. The first command in main(), for this programme, is to stream a string to the standard output (console). The next is to return i.e. to end.

    In more complex programmes one might want {while(no user input){action}}, but here it's really simple. The other reason for saying No is in C++ while is a loop, so your logic would produce many, many "hello, world" s. However, only one is required.

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following 2 Users Say Thank You to demolition For This Useful Post:
    nicholes, StefanL

     
    StefanL | # 27 | 2011-06-16, 18:12 | Report

    Originally Posted by demolition View Post
    No. The sole purpose of this programme is to produce an output i.e. "hello, world". Nothing else. The only user input should be to run the programme, that's it. The slight glitch can be that the console disappears so fast the output cannot be read hence my alternate version, which does require user input.

    The entry point of a C++ programme is main(), or pseudo-name thereof. The first command in main(), for this programme, is to stream a string to the standard output (console). The next is to return i.e. to end.

    In more complex programmes one might want {while(no user input){action}}, but here it's really simple. The other reason for saying No is in C++ while is a loop, so your logic would produce many, many "hello, world" s. However, only one is required.
    Thanks, I was thinking along of the lines of introducing the OP to event driven programming rather than linear programming, which I thought is more relevant today. Also the next logical step in any extension to this programming excercise would be to echo user input, which then just needs a user input processing routine in the loop. But there is really no need to get ahead of the game at this point.

    I do agree that the linear programming does the job probably with the smallest effort and tightest code.

    Edit | Forward | Quote | Quick Reply | Thanks

    Last edited by StefanL; 2011-06-16 at 18:16.

     
    nicholes | # 28 | 2011-06-17, 09:24 | Report

    One more qustion
    #include <iostream>


    int main()
    {
    int s; //salry

    printf("enter your salary");
    scanf ("%d",&s);
    if (s>=1000)
    {
    if (s>=3000)
    {
    if (s>=5000)
    printf ("your bonus is 500");

    else
    printf("your bonus is300");
    }
    else
    printf("your bonus is100");
    }
    else
    printf("no bonus");
    system("PAUSE");
    }



    it execute and works perfact but
    shause not found comes!! Any way to get rid of it

    Edit | Forward | Quote | Quick Reply | Thanks
    Attached Images
     

     
    demolition | # 29 | 2011-06-17, 10:00 | Report

    Now, you really need to stop using C standard functions, like printf and scanf. The C++ equivalents make the code easier to read and are *just as well implemented* in the STL (standard template library). C code will normally compile because C++ is a superset of C and some software, e.g. win32, hasn't been fully converted to C++ yet.

    Next, as mentioned above, system("pause") doesn't work outside dos/windows. If your programme just runs and exits without you being able to see the output try my v2. It seems you are very new to programming overall - no worries and well done for giving it a go.

    Amongst other paradigms, Encapsulation and Abstraction are part of the bedrock of C++, as an OO language. In programming, encapsulation means wrapping functionality together. And, abstraction means removing or separating one bit of functionality from another.

    I will edit this post in a minute with the C++ version of your code.

    ps - any chance you can either start a new thread or remove the Solved if you've got more questions. Bit misleading otherwise.

    Edit | Forward | Quote | Quick Reply | Thanks

     
    Captwheeto | # 30 | 2011-06-17, 10:48 | Report

    Yeah I said this earlier. You're writing just plain C in a very procedural manner, I think you need to look for a better C++ resource, one that is aimed at linux or uses standard headers, operators and such.

    You could learn C if you like, I would recommend it over C++, but if you're looking for a career in programming then stick with OO languages like Python, C++ or Java

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following User Says Thank You to Captwheeto For This Useful Post:
    demolition

     
    Page 3 of 4 | Prev |   1     2   3   4   | Next
vBulletin® Version 3.8.8
Normal Logout