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!
Code:
/////////////////////////////////
// WORK IN PROGRESS //
////////////////////////////////
//compilable
// 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<<"* *"<<endl;
cout<<"* WELCOME TO THE VIDEO STORE! *"<<endl;
cout<<"* *"<<endl;
cout<<"*******************************"<<endl<<endl;
do{
cout<<"OPTIONS:"<<endl<<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: ";
cin>>selection;
cout<<endl;
if(cin.good() && selection > 0 && selection < 5){
if(selection == 1 || selection == 3){//selections that require a movie title
cin.ignore();
cout<<"Enter the title of the movie."<<endl<<"Title: ";
cin.getline(user_input_title,81);
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;
rent_movie(movie);
}
}
else if(selection == 2){ //selection 2 will print all movies available
print_movies_available(movie_library, number_of_movies);
}
else {
cout<<"Goodbye."<<endl;
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!