C or C++

This is a discussion on C or C++ within the C++ Programming forums, part of the General Programming Boards category; Could someone please tell me the differences between C and C++? I know Visual Basic fairly well and want to ...

  1. #1
    Registered User NewbieVB's Avatar
    Join Date
    Apr 2002
    Posts
    41

    Question C or C++

    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 ---

  2. #2
    Seņor Member
    Join Date
    Jan 2002
    Posts
    561
    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.

  3. #3
    Registered User NewbieVB's Avatar
    Join Date
    Apr 2002
    Posts
    41
    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 ---

  4. #4
    Registered User NewbieVB's Avatar
    Join Date
    Apr 2002
    Posts
    41
    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 ---

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >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.

  6. #6
    Registered User Strider's Avatar
    Join Date
    Aug 2001
    Posts
    149
    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:
    Code:
    #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;
    }
    David
    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.

  7. #7
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    Originally posted by tim545666
    VB is trash.
    Yeah, but it pays the bills.

    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.

  8. #8
    Registered User NewbieVB's Avatar
    Join Date
    Apr 2002
    Posts
    41
    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 ---

  9. #9
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    To get real random numbers:

    #include <time.h>

    srand((unsigned)time(NULL));
    int i=(rand()%5)+1;

    This gives you 1 - 5;

  10. #10
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >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++
    Code:
    #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;
    }
    -Prelude
    My best code is written with the delete key.

  11. #11
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    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.

  12. #12
    Registered User NewbieVB's Avatar
    Join Date
    Apr 2002
    Posts
    41
    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 ---

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21