Thread: My best C++ Programs

  1. #91
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    Posts
    160
    tim:

    heres my algorithm for randomizing numbers

    Code:
    #include <iostream.h>
    #include <time.h>
    #include <stdlib.h>
    
    const int HIGH = 10;
    const int LOW = 1;
    
    int main()
    {
             time_t seconds; //seconds is variable for time
             time(&seconds);
             srand((unsigned int) seconds);
             int num;
    
             num= rand() % (HIGH - LOW + 1) + LOW;
    
             cout<<num<<endl;
             return 0;
    }
    that will give you a number between 1 and 10
    Paro

  2. #92
    Unregistered
    Guest
    Is that any better than mine Paro?

    Code:
    srand( time( NULL ) );
    cout << (rand( )% 10) + 1 << endl;

  3. #93
    Registered User
    Join Date
    Feb 2002
    Posts
    57

    My method for random numbers

    #include <iostream.h>
    #include <windows.h>

    int main()
    {
    int randnum;

    srand(GetTickCount());
    randnum = rand()%101;

    }

    -From gamtutorials , it works good. Just make sure you call srand before rand()
    Language: C++
    Compiler: Visual C++ 6.0
    Currently Working On: Simple OpenGL aspects

  4. #94
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    Posts
    160
    to Unregistered:

    I think they work exactly the same, its just the way i did it is like using C instead of C++, its just older...

    actually maybe theres a better way of putting it... its like im re-inventing it each time instead of doing it the short and easy way...

    its the way i learned it and its the way i know it, so thats how i use it
    Paro

  5. #95
    Registered User
    Join Date
    Mar 2002
    Posts
    6

    Gah!

    I looked away for two days and now my reply seems vaguely rememberable. Heh, oh well. Reply to the strength of Paro's coding class.

    I'm ahead of my class, we know basic single-dimension arrays and functions as voids/ints/char kind of things. I'm actually ahead of the classing with using structs/member functions in c/c++. Now I'm preparing to use two dimensional arrays. Teacher seems proud of me. He has me participating in this Great Computer Challenge. Any of you in the VA area going to be there?

  6. #96
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    Posts
    160
    whats the VA?
    Paro

  7. #97
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    > whats the VA?

    Virginia...

  8. #98
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    Posts
    160
    oh, i live in washington
    Paro

  9. #99
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330
    Code:
    template <class T>
    T random(T min, T max)
    {
        srand ( unsigned (time(NULL)) );
        return T (rand() % (max - min + 1)) + min;
    }
    That's what I use for randomitivity.

  10. #100
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    Posts
    160
    i havent gotten into templates yet, right now were learning the basics of Classes, and then the arrays...which goes to 2d arrays i think...

    i pretty much know how to use arrays in a limited way like:

    int j[10];

    which is much better than:

    int j1, j2, j3, j4, j5, j6, j7, j8, j9, j10;

    heheheh
    Paro

  11. #101
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    Posts
    160
    oh rmullen, were you talking about "random.h"? thats what you used for random.h? cuz i couldnt run your program...hey how bout you put the exe file out for us to test


    oh hey this is the 100 post on my thread woohoo
    Paro

  12. #102
    Seņor Member
    Join Date
    Jan 2002
    Posts
    560
    Paro, the tough part is making a true deck, with 1 of every card in each suit. Try it, there's plenty of ways to do it.

  13. #103
    Registered User
    Join Date
    Mar 2002
    Posts
    4

    in .cpp?

    hi can u upload your fil in .cpp,or others, not .zip?

  14. #104
    Registered User Paro's Avatar
    Join Date
    Feb 2002
    Posts
    160
    tell me if this is the right one...i cant remember hehe
    Paro

  15. #105
    Registered User
    Join Date
    Mar 2002
    Posts
    4
    yes Paro
    that's your semester project
    what year are you doing now?
    year 1

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Recommend upgrade path for C programs
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-22-2007, 07:32 AM
  2. How come Dev C++ cant run some programs??
    By Sephiroth in forum C Programming
    Replies: 41
    Last Post: 09-17-2005, 05:35 AM
  3. Way to get the current open programs displayed?
    By CPPguy1111 in forum C++ Programming
    Replies: 6
    Last Post: 06-22-2005, 12:24 AM
  4. POSIX/DOS programs?
    By nickname_changed in forum C++ Programming
    Replies: 1
    Last Post: 02-28-2003, 05:42 AM
  5. executing c++ programs on the web
    By gulti01 in forum C++ Programming
    Replies: 4
    Last Post: 08-12-2002, 03:12 AM