| The Following User Says Thank You to onethreealpha For This Useful Post: | ||
|
|
2011-06-17
, 11:21
|
|
|
Posts: 1,102 |
Thanked: 368 times |
Joined on Oct 2010
@ india, indore
|
#32
|
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.
|
|
2011-06-17
, 11:22
|
|
Posts: 189 |
Thanked: 47 times |
Joined on Nov 2009
|
#33
|
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");
}
#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;
}
|
|
2011-07-08
, 17:34
|
|
|
Posts: 850 |
Thanked: 626 times |
Joined on Sep 2009
@ Vienna, Austria
|
#34
|
i have been told to learn C before starting c++ to learn basics of codes etc
| The Following User Says Thank You to SubCore For This Useful Post: | ||
![]() |
| Tags |
| i am sleeping |
| Thread Tools | |
|
i found it great when I started learning C++
Always remember you're unique, just like everyone else.