Could someone please tell me the differences between C and C++? I know Visual Basic fairly well and want to move up to either C or C++, which is for me? I can't decide because I dont know the differences.
If you have time check out NewbieVB.com
Could someone please tell me the differences between C and C++? I know Visual Basic fairly well and want to move up to either C or C++, which is for me? I can't decide because I dont know the differences.
If you have time check out NewbieVB.com
Compiler: Metrowerks Codewarrior 7
--- I may be a newbie but theres no need to make fun ---
VB is trash.
Anyway, you're going to get biased results because you posted this on the C++ board. It would have been better to post on the C board. Anyway, C++ is an improved C. It adds classes, overloading, and some other junk. I personally think that C++ code looks a little cleaner, but others may argue otherwise. If you learn C++ and decide you like C better, it is an easy transition, and vise versa. I'd say go with C++ because it seems to be more widely used, unless you want to write operating systems. C and ASM are used in OS's.
Yeah, I guess go with C++ but you won't go wrong either way.
Okay, I think I will learn C++.
Also I need C++ for grade 12 computers (that's in 2 years but...who cares)
Compiler: Metrowerks Codewarrior 7
--- I may be a newbie but theres no need to make fun ---
I don't mean to keep replying to my own message but look, an hour or so after I posted this reply look what I can do:
#include <iostream.h>
int main()
{
cout<<"Choose a number between 1 - 5";
cin>> num
if (num = 1)
{
cout<<"Good Job you guessed the number!";
}
else
{
cout<<"Sorry, that wasn't the number";
}
end if
return 0;
}
Compiler: Metrowerks Codewarrior 7
--- I may be a newbie but theres no need to make fun ---
>an hour or so after I posted this reply look what I can do
Not bad, now make it so that the program decides the number.
-Prelude
My best code is written with the delete key.
Hey that's neat, but (num = 1) will always be true and there is no end if in C or C++.
This is what you want:
DavidCode:#include <iostream.h> int main() { cout<<"Choose a number between 1 - 5"; cin>> num if (num == 1) { cout<<"Good Job you guessed the number!"; } else { cout<<"Sorry, that wasn't the number"; } return 0; }
One Ring to rule them all, One Ring to find them,
One Ring to bring them all and in the darkness bind them
In the Land of Mordor where the Shadows lie.
Yeah, but it pays the bills.Originally posted by tim545666
VB is trash.
On a side note, I started with C ( a LONG time ago ) and then moved to VB after very little time with C ( I gave up! :: kicks self for not sticking with it in the first place :: ) and after many years with VB I finally moved to C++.
The knowledge I had from my little experience with C made learning C++ much easier ( at least I think it did ) but if I had it to do it all over again I'd just have started with C++ in the first place.
A crap, I made a mistake, thanks for telling me to put the == also I am not a retard programmer I program VB and can make some pretty decent programs.
Someone tell me how I could randomize numbers in C++ in VB its:
variable = int(rnd*5)+1 'this would make the number between 1 and 5
Compiler: Metrowerks Codewarrior 7
--- I may be a newbie but theres no need to make fun ---
To get real random numbers:
#include <time.h>
srand((unsigned)time(NULL));
int i=(rand()%5)+1;
This gives you 1 - 5;
>To get real random numbers:
To get pseudorandom numbers that change with every execution of the program.
>Someone tell me how I could randomize numbers in C++
-PreludeCode:#include <iostream> #include <ctime> using namespace std; int main() { int num; cout<<"Choose a number between 1 - 5: "; cin>>num; srand ( time ( NULL ) ); if ( num == 1 + ( rand() % 5 ) ) cout<<"Good Job you guessed the number!\n"; else cout<<"Sorry, that wasn't the number\n"; return 0; }
My best code is written with the delete key.
Granted I used real out of context, but I was trying to point out the importance of using srand and basing the return off of the time.
Also, why would this only change with each new execution of the program? In my own random number generator I use srand on each call. So as often as the function is called, srand's return is reset to something new.
Okay thanks for showing me how to do the randomized number in C++ but first I am going to get all the basics straight.
Compiler: Metrowerks Codewarrior 7
--- I may be a newbie but theres no need to make fun ---