Reply
Thread Tools
onethreealpha's Avatar
Posts: 434 | Thanked: 990 times | Joined on May 2010 @ Australia
#31
Good beginners website HERE if you're interested in C++

i found it great when I started learning C++
__________________
Always remember you're unique, just like everyone else.
 

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

get your smooth live wallpaper today
My YouTube videos
 
Posts: 189 | Thanked: 47 times | Joined on Nov 2009
#33
Originally Posted by nicholes View Post
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

Last edited by lfcobra; 2011-06-17 at 11:46.
 
SubCore's Avatar
Posts: 850 | Thanked: 626 times | Joined on Sep 2009 @ Vienna, Austria
#34
Originally Posted by nicholes View Post
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++?
__________________
"What we perceive is not nature itself, but nature exposed to our method of questioning."
-- Werner Karl Heisenberg
 

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

Tags
i am sleeping


 
Forum Jump


All times are GMT. The time now is 08:10.