Thread: A lottery program - arrays, ints, chars etc

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    62

    A lottery program - arrays, ints, chars etc

    Hello,

    Im going to create a C++ "database".
    It should be 3 dimensional (i.e. A person has some classess, each class requires different books etc.). And the database must sort that info aswell.

    For various reasons, I want the user to be able to search the "database" - in a very easy way. Say that, after that the user has stored info about the persons and classes, he will be asked if he wants to search that info, and if yes, he should be able to find the results in such a way, that even if spelled wrong, he would get close results.



    This is for educational purposes only. Please keep in mind that I am a starter with C++, and know the basic syntax, so advanced stuff beyond arrays, loops, pointers etc. is not really necessary in the program, please avoid using functions all over the program where it can be avoided, so I understand the principles.

    Thank you for reading this.

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    And your questions is?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Super unModrator
    Join Date
    Dec 2007
    Posts
    321
    Quote Originally Posted by Glauber View Post
    please avoid using functions all over the program where it can be avoided, so I understand the principles.
    Quote Originally Posted by Elysia View Post
    And your questions is?
    Got it now? Its not a question, he is just requesting you not to use functions
    Last edited by abh!shek; 05-17-2008 at 10:18 AM.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yeah, I understand, but I'm not going to write anything.
    So I was asking if the OP had a specific question he/she did not understand in developing such a program?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Jun 2007
    Posts
    41
    These, "Hey, you do not have anything better to do, write my program for me!", kinds of threads always make me chuckle. What a better way to learn then do nothing and have someone else do all the work.

  6. #6
    Registered User
    Join Date
    May 2008
    Posts
    62
    Quote Originally Posted by Elysia View Post
    Yeah, I understand, but I'm not going to write anything.
    So I was asking if the OP had a specific question he/she did not understand in developing such a program?
    For example. How can you store a char array in an int array? If you want a certain number to be assigned in each loop in a for loop, to a char array?

    Example: for(i=0; numberofplayers>i; i++){
    cin >> playernames[30];
    playernames[30]=playernumber[i];


    That dosent work. But I hope you get the idea.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Chars are integers, so you can easily store a character in an integer at will.
    What I think you want is the ability to enter and store multiple names for the user.
    In such case, std::vector and std::string will be your friends.

    Code:
    std::vector<std::string> vPlayers;
    vPlayers.reserve(30);
    for(i=0; numberofplayers>i; i++){
    cin >> playernames[i];
    }
    If you need to associate an id with a certain player, use a struct:

    Code:
    struct Player
    {
        std::string name;
        int nId;
    };
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    even if spelled wrong, he would get close results
    http://en.wikipedia.org/wiki/Levenshtein_distance

    I doubt you will be able to do it though if you are just starting out.

  9. #9
    Registered User
    Join Date
    May 2008
    Posts
    62
    Quote Originally Posted by Elysia View Post
    Chars are integers, so you can easily store a character in an integer at will.
    What I think you want is the ability to enter and store multiple names for the user.
    In such case, std::vector and std::string will be your friends.

    Code:
    std::vector<std::string> vPlayers;
    vPlayers.reserve(30);
    for(i=0; numberofplayers>i; i++){
    cin >> playernames[i];
    }
    If you need to associate an id with a certain player, use a struct:

    Code:
    struct Player
    {
        std::string name;
        int nId;
    };
    I'm not familiar with the std::string syntax. What does "::" mean in the context?

  10. #10
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229

  11. #11
    Registered User
    Join Date
    May 2008
    Posts
    62
    Quote Originally Posted by Elysia View Post
    If you need to associate an id with a certain player, use a struct:

    Code:
    struct Player
    {
        std::string name;
        int nId;
    };
    How would do if you later wanted to cout the whole Player struct using only the Id of a certain player?

    For example, if you have
    Code:
       
     struct data 
        {
               int id;
               string player;
               string partner;
               string team;
        };
    And want to associate an id with all of those strings?
    So that a certain player, partner and team, will be associated with that id?



    NEXT question is: How do you do if you want to request only 1 specific STRING from the struct, using only the id?
    Last edited by Glauber; 05-25-2008 at 10:17 AM.

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Then you would use a map. Use the id as a key and the struct (possible a pointer) as the data.
    In that way, you can search in the map for the struct associated with the id. Inside the struct is all the data about the player, so you can pick the data you want from the struct.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    Registered User
    Join Date
    May 2008
    Posts
    62
    Quote Originally Posted by Elysia View Post
    Then you would use a map. Use the id as a key and the struct (possible a pointer) as the data.
    In that way, you can search in the map for the struct associated with the id. Inside the struct is all the data about the player, so you can pick the data you want from the struct.
    How would you do that in the example provided?

  14. #14
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Code:
    std::map<int, Player> mIdToPlayer;
    mIdToPlayer[Id] = struct;
    std::map<int, Player>::iterator i = mIdToPlayer.lookup(Id);
    if (i != mIdToPlayer.end())
        Player struct = i->second;
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A simple program using ARRAYS, STRUCTS, and CLASSES
    By CStudentHelp in forum C++ Programming
    Replies: 8
    Last Post: 04-17-2008, 09:57 PM
  2. converting ints to chars
    By e66n06 in forum C Programming
    Replies: 4
    Last Post: 07-28-2007, 03:52 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM