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)

onethreealpha 2011-06-17 11:08

Re: [solved](.cpp)"Hello world" in n900 (getting error) plz guide me.
 
Good beginners website HERE if you're interested in C++

i found it great when I started learning C++

nicholes 2011-06-17 11:21

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

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

well since my teacher is teaching me only C not C++ for now and,i have been told to learn C before starting c++ to learn basics of codes etc. so i would programme under C only for now but later i would expand....

also my problem is solved by execute the .cpp so i changed the thread title by "[solved]" and for small questions i don't want to start a new thread and become a part of spam!!(no offence plz)

again Thanks to all of you!

lfcobra 2011-06-17 11:22

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

Originally Posted by nicholes (Post 1030721)
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");
}

just a quick couple of tips. As previously stated try to use the actual c++ functions instead of the c funtions. They will make the code much easier to read, and also avoid unnecessary code complexity with unneeded nesting

Code:

#include <iostream.h>       
#include <stdio.h>

int main(){
using namespace std;
int s; //salary

cout << "Enter your salary: " ;
cin >> s;

if (s>=5000)
  cout << "Your bonus is 500";
else if (s>=3000)
  cout << "Your bonus is 300";
else if (s>=1000)
  cout << "Your bonus is 100";
else
  cout << "No bonus";
getchar();

return 0;
}

note: this code should work but i didnt get a chance to compile it.

edit: just saw your post about being taught C so you can disregard my comment about using c++ functions :)

SubCore 2011-07-08 17:34

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

Originally Posted by nicholes (Post 1030774)
i have been told to learn C before starting c++ to learn basics of codes etc

that's not a good idea. it's a waste of time actually: Should I learn C before I learn OO/C++?


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

vBulletin® Version 3.8.8