Thread: trying to get a few functions to work properly...

  1. #1
    Registered User
    Join Date
    Jul 2009

    Question trying to get a few functions to work properly...

    Hey all,

    Im pretty new to c++ and alot of the constructs I am using in this program - strings, functions, pointers, arrays, structures etc.

    The main below is fleshed out and is compiling correctly. I am having difficulty passing around values and getting my three functions in this program to work properly. I have the arguments and parameters allready set up for each function as a skeleton and I have commented in each of the three functions what I am trying to get them to do.

    Any help w/my functions is greatly appreciated!

    //       WORK IN PROGRESS     //
    // This is a program for "renting" movies. There are only two movies that will be used in the
    // program - Jurassic Park & Lord of the Rings. The user can do a search for a movie
    // (only Jurassic Park or Lord of the Rings will produce a result as they are the 
    // only ones that will be used for the time being), view all the movies 
    // not currently "rented", and then proceed to "rent" a movie 
    // thus making it unavailable at that point. Each option corresponds
    // to a function set up in the 
    // selection menu set up in main.
    #include <iostream>
    using namespace std;
    struct movie_structure {
           char movie_name[40];
           char director[40];
           char product_number[10];
           bool rented;
    void rent_movie (movie_structure* movie)
    //Will "rent" a movie making it no longer available (i.e. set boolean value to true)
    movie_structure* get_movie (movie_structure movie_library[], char* movie_name, int library_size)
    //will return a pointer to a movie based on title supplied, else will return null pointer
    void print_movies_available (movie_structure movie_library[], int library_size)
    //will display the movies not currently "rented" (i.e. movies w/false boolean value) 
    int main()
        char user_input_title[81]; // user's input
        movie_structure* movie; // movie pointer 
        int selection = 0;   // for the menu selections
        int number_of_movies = 2;  // number of movies in the 'movie library'
        movie_structure movie_library[] = {  //title               //director          //product #'s   //boolean value
                                             {"Jurassic Park",     "Steven Spielberg", "913564180",     0},
                                             {"Lord of the Rings", "Peter Jackson",    "376145212",     0}
        cout<<"*                             *"<<endl;
        cout<<"* WELCOME TO THE VIDEO STORE! *"<<endl;
        cout<<"*                             *"<<endl;
           cout<<"1 - Search for a movie."<<endl<<endl;
           cout<<"2 - View all available movies."<<endl<<endl;
           cout<<"3 - Rent a movie."<<endl<<endl;
           cout<<"4 - Exit store."<<endl<<endl;
           cout<<"SELECTION: ";
           if(cin.good() && selection > 0 && selection < 5){
             if(selection == 1 || selection == 3){//selections that require a movie title
               cout<<"Enter the title of the movie."<<endl<<"Title: ";
               movie = get_movie(movie_library, user_input_title, number_of_movies);  
               if (movie == NULL)  //invalid title
                    cout<<endl<<user_input_title<<" not found. Try again."<<endl<<endl;
               else if (movie->rented == true) //valid movie, but movie is currently "rented"
                    cout<<movie->movie_name<<" is checked out. Sorry!"<<endl<<endl;
               else if (selection == 1) //movie available for "rent"
                    cout<<endl<<movie->movie_name<<" by "<<movie->director<<" is available."<<endl<<endl;
               else{  //movie available
                     cout<<endl<<movie->movie_name<<" is available. Let me check it out for you!"<<endl<<endl;
             else if(selection == 2){ //selection 2 will print all movies available
                print_movies_available(movie_library, number_of_movies); 
             else {
               return 0;
           else {   //invalid selection
              cout<<endl<<"Invalid selection."<<endl<<endl;
              selection = 1;
         while(selection < 4);
        return 0;

    Any input, tips, or coding ideas?

    Thanks for your help!

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Waterloo, Texas
    >> I am having difficulty passing around values and getting my three functions in this program to work properly.

    Yes well the main problem is that the functions are completely empty. Why don't you write some code to fill those in and then ask more questions along the way as necessary, rather than just expect someone else to fill the code in for you?
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
        return std::pow
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    United States
    Basically I think you just need to know about search algorithms to do this. - Discussion Articles - Efficient Searching from Sequential to Binary Search and Beyond

  4. #4
    Webhead Spidey's Avatar
    Join Date
    Jul 2009
    Well since your limited to only two movies, I'd say a linear search wold suffice which loops through all elements in your structure and sees if there is a match to the one you are currently looking for.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can't get fgets to work properly
    By lonkz in forum C Programming
    Replies: 18
    Last Post: 01-03-2009, 01:43 PM
  2. Replies: 5
    Last Post: 01-18-2006, 08:59 AM
  3. functions don't work!
    By geek987 in forum C++ Programming
    Replies: 7
    Last Post: 10-10-2002, 07:51 PM
  4. pointers to class functions?
    By btq in forum C++ Programming
    Replies: 1
    Last Post: 08-19-2002, 04:17 PM