maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Nokia N900 (https://talk.maemo.org/forumdisplay.php?f=44)
-   -   [solved](.cpp)"Hello world" in n900 (getting error) plz guide me. (https://talk.maemo.org/showthread.php?t=74021)

demolition 2011-06-16 13:14

Re: (.cpp)"Hello world" in n900 (getting error) plz guide me.
 
Quote:

Originally Posted by SubCore (Post 1030193)
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....

nicholes 2011-06-16 13:16

Re: (.cpp)"Hello world" in n900 (getting error) plz guide me.
 
1 Attachment(s)
Quote:

Originally Posted by SubCore (Post 1030078)
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)

SubCore 2011-06-16 13:27

Re: (.cpp)"Hello world" in n900 (getting error) plz guide me.
 
Quote:

Originally Posted by nicholes (Post 1030238)
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).

nicholes 2011-06-16 13:32

Re: (.cpp)"Hello world" in n900 (getting error) plz guide me.
 
Quote:

Originally Posted by SubCore (Post 1030242)
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!!!!!!!!:)

StefanL 2011-06-16 13:54

Re: [solved](.cpp)"Hello world" in n900 (getting error) plz guide me.
 
Not being a real C or C++ programmer, should the logic of the program not be something like:

While no user input -> Hello World.

:confused:

demolition 2011-06-16 14:44

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

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

While no user input -> Hello World.

:confused:

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.

StefanL 2011-06-16 18:12

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

Originally Posted by demolition (Post 1030290)
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.

nicholes 2011-06-17 09:24

Re: [solved](.cpp)"Hello world" in n900 (getting error) plz guide me.
 
1 Attachment(s)
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
sh:pause not found comes!! Any way to get rid of it

demolition 2011-06-17 10:00

Re: [solved](.cpp)"Hello world" in n900 (getting error) plz guide me.
 
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.

Captwheeto 2011-06-17 10:48

Re: [solved](.cpp)"Hello world" in n900 (getting error) plz guide me.
 
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


All times are GMT. The time now is 16:29.

vBulletin® Version 3.8.8