Page 1 of 4 1234 LastLast
Results 1 to 10 of 31

Thread: My C++ games

  1. #1
    OlegL's Avatar Poster
    Join Date
    May 2009
    Location
    New York City
    Age
    36
    Posts
    1,799
    This is one of the games I created in C++:

    #include <ctime>
    #include <cstdlib>
    #include <cmath>
    #include <iostream>
    using namespace std;

    const int SIZE = 100;

    void initGame(int[], const int);
    void printGame(int[], const int);
    int findMin(int[], const int);
    int findMax(int[], const int);
    int guess();
    bool found(int[], const int, int);

    int main()
    {
    srand(time(0));
    int game[SIZE];
    initGame(game, SIZE);
    // printGame(game, SIZE);
    cout << "The minimum value in the array is " << findMin(game, SIZE) << endl;
    cout << "The maximum value is " << findMax(game, SIZE) << endl;
    bool quit = false;
    while (quit == false)
    {
    int value = guess();
    bool value_found = found(game, SIZE, value);
    if (value_found == true)
    cout << "Your value was found in the game\n";
    if (value_found == false)
    cout << "Your value wasn't found in the game\n";
    cout << "Do you want to guess again or quit?"
    " If you want to quit, type q\n"
    "If you want to guess again, type any other key: ";
    char answer;
    cin >> answer;
    if (answer == 'q')
    quit = true;
    }
    }
    void initGame(int int_array[], const int length)
    {
    for (int i = 0; i < length; i++)
    int_array[i] = rand() % 1000 + 1;
    }


    void printGame(int int_array[], const int length)
    {
    for (int i = 0; i < length; i++)
    cout << int_array[i] << endl;
    }

    int findMin(int int_array[], const int length)
    {
    int smallest = int_array[0];
    for (int i = 1; i < length; i++)
    {
    if (int_array[i] < smallest)
    smallest = int_array[i];
    }
    return smallest;
    }

    int findMax(int int_array[], const int length)
    {
    int largest = int_array[0];
    for (int i = 1; i < length; i++)
    {
    if (int_array[i] > largest)
    largest = int_array[i];
    }
    return largest;
    }

    int guess()
    {
    int value = 1;
    while (value != 0)
    {
    cout << "Please enter a value between 1 and 1000: ";
    cin >> value;
    if (value >= 1 && value <= 1000)
    {
    break;
    }
    if (value == 0)
    {
    cout << "You decided to exit the program. Bye.\n";
    exit(0);
    }
    }
    return value;
    }

    bool found(int int_array[], const int length, int value)
    {
    bool value_found = false;
    for (int i = 0; i < length; i++)
    {
    if (value == int_array[i])
    value_found = true;
    }
    return value_found;
    }


    Later, I will post some other games I created in C++.
    Last edited by OlegL; 08-29-2011 at 05:40 PM.

  2. Internet, Programming and Graphics   -   #2
    tesco's Avatar woowoo
    Join Date
    Aug 2003
    Location
    Canadia
    Posts
    24,069
    compile it and post.

  3. Internet, Programming and Graphics   -   #3
    OlegL's Avatar Poster
    Join Date
    May 2009
    Location
    New York City
    Age
    36
    Posts
    1,799
    By the way, that code has one error, which is this line: int_array[i] = rand() % 1001 + 1. It should be 1000 + 1, not 1001 + 1.

  4. Internet, Programming and Graphics   -   #4
    Disme's Avatar I'm Belgian BT Rep: +7BT Rep +7
    Join Date
    Dec 2006
    Posts
    2,623
    What made you think anyone cared ...
    Can you feel the LOVE

  5. Internet, Programming and Graphics   -   #5
    OlegL's Avatar Poster
    Join Date
    May 2009
    Location
    New York City
    Age
    36
    Posts
    1,799
    Don't make strange comments please.

  6. Internet, Programming and Graphics   -   #6
    Disme's Avatar I'm Belgian BT Rep: +7BT Rep +7
    Join Date
    Dec 2006
    Posts
    2,623
    Don't make strange posts please ...
    Can you feel the LOVE

  7. Internet, Programming and Graphics   -   #7
    bijoy's Avatar secret lover BT Rep: +1
    Join Date
    Aug 2010
    Posts
    1,834
    Compile it & upload anywhere, not in bt sites & post the link here
    Teh n00b.

  8. Internet, Programming and Graphics   -   #8
    whatcdfan's Avatar A.W.A BT Rep: +2
    Join Date
    Jun 2010
    Posts
    1,452
    Quote Originally Posted by bijoy View Post
    Compile it & upload anywhere, not in bt sites & post the link here
    Dont make serious posts in OlegL thread please....

  9. Internet, Programming and Graphics   -   #9
    bijoy's Avatar secret lover BT Rep: +1
    Join Date
    Aug 2010
    Posts
    1,834
    Quote Originally Posted by whatcdfan View Post
    Quote Originally Posted by bijoy View Post
    Compile it & upload anywhere, not in bt sites & post the link here
    Dont make serious posts in OlegL thread please....
    I thought he was somewhat different in this thread.
    Teh n00b.

  10. Internet, Programming and Graphics   -   #10
    OlegL's Avatar Poster
    Join Date
    May 2009
    Location
    New York City
    Age
    36
    Posts
    1,799
    There is no need to post executables anywhere.

Page 1 of 4 1234 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •