Active Topics

 


Reply
Thread Tools
Posts: 560 | Thanked: 422 times | Joined on Mar 2011
#21
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....
 

The Following User Says Thank You to demolition For This Useful Post:
nicholes's Avatar
Posts: 1,103 | Thanked: 368 times | Joined on Oct 2010 @ india, indore
#22
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)
Attached Images
 
__________________
N900 gave me a reason to live in this cruel world

get your smooth live wallpaper today
My YouTube videos

Last edited by nicholes; 2011-06-16 at 13:19.
 
SubCore's Avatar
Posts: 850 | Thanked: 626 times | Joined on Sep 2009 @ Vienna, Austria
#23
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).
__________________
"What we perceive is not nature itself, but nature exposed to our method of questioning."
-- Werner Karl Heisenberg
 

The Following 2 Users Say Thank You to SubCore For This Useful Post:
nicholes's Avatar
Posts: 1,103 | Thanked: 368 times | Joined on Oct 2010 @ india, indore
#24
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!!!!!!!!
__________________
N900 gave me a reason to live in this cruel world

get your smooth live wallpaper today
My YouTube videos
 

The Following User Says Thank You to nicholes For This Useful Post:
StefanL's Avatar
Posts: 298 | Thanked: 341 times | Joined on Aug 2010 @ This world :)
#25
Not being a real C or C++ programmer, should the logic of the program not be something like:

While no user input -> Hello World.

__________________
My phone evolution: Nokia 7610 (RIP), N82 (RIP), BB9000 (RIP), N900, BB9760 (RIP), N8, BB9900, N9 64GB
Working : Python Gorillas (Maemo5) Faircrack0.50 Update (Maemo5)
Not so much : WPScrack (Maemo5)
 
Posts: 560 | Thanked: 422 times | Joined on Mar 2011
#26
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.
 

The Following 2 Users Say Thank You to demolition For This Useful Post:
StefanL's Avatar
Posts: 298 | Thanked: 341 times | Joined on Aug 2010 @ This world :)
#27
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.
__________________
My phone evolution: Nokia 7610 (RIP), N82 (RIP), BB9000 (RIP), N900, BB9760 (RIP), N8, BB9900, N9 64GB
Working : Python Gorillas (Maemo5) Faircrack0.50 Update (Maemo5)
Not so much : WPScrack (Maemo5)

Last edited by StefanL; 2011-06-16 at 18:16.
 
nicholes's Avatar
Posts: 1,103 | Thanked: 368 times | Joined on Oct 2010 @ india, indore
#28
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
Attached Images
 
__________________
N900 gave me a reason to live in this cruel world

get your smooth live wallpaper today
My YouTube videos
 
Posts: 560 | Thanked: 422 times | Joined on Mar 2011
#29
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's Avatar
Posts: 302 | Thanked: 193 times | Joined on Oct 2008 @ England
#30
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
 

The Following User Says Thank You to Captwheeto For This Useful Post:
Reply

Tags
i am sleeping


 
Forum Jump


All times are GMT. The time now is 19:48.