I get the idea but I'm not sure how to code it

Hi I'm creating a program to rent some movies and to return movies with a balance starting at $100. I'm making a main menu for the user to input what choices they would like to make.
I'm stuck on how to move forward like what else should I do in the case statements? Thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <iostream>
#include "movie.h"
#include "Account.h"
#include <string>


using namespace std;


int main()
{
	//create 10 movie objects
					   //name,              date,  genre, not rented, cost($ per day)
	movie title1("The Shawshank Redemption", 1994, "drama", 0, 5);
	movie title2("Pulp Fiction", 1994, "drama", 0, 5);
	movie title3("Fight Club", 1999, "drama", 0, 5);
	movie title4("Star Wars: Episode V - The Empire Strikes Back", 1980, "sci-fi", 0, 5);
	movie title5("Goodfellas", 1990, "drama", 0, 4);
	movie title6("The Matrix", 1999, "sci-fi", 0, 4);
	movie title7("Se7en", 1995, "mystery", 0, 4);
	movie title8("The Silence of the Lambs", 1991, "drama", 0, 4);
	movie title9("Leon: The Professional", 1994, "drama", 0, 3);
	movie title10("American History X", 1998, "drama", 0, 3);

	//create an array storing these 10 movie objects
	//create array of all movie titles/objects
	movie arraymovie[10] = { title1, title2, title3, title4, title5, title6, title7, title8, title9, title10 };
	//account object
	//Account name,   ID,    Balance ($)
	Account newaccount("User1", 12345, 100);


	//create a function to display the list of movies that are available to be rented 
	//i.e.those that have not been rented

	//Enter while loop 
	while (true)
	{	
		int menu = 0;
		int i = 0;
		int temp = 0;
		int movie = 0;

		cout << "Your balance is $" << newaccount.getbalance() << endl;
		cout << "Select 1 to rent a movie \n";
		cout << "Select 2 to return a movie \n";
		cout << "Select 3 to view my account \n";
		cout << "Select 4 to exit \n";
		cin >> temp;
		
		/*make sure the user input choice is a valid integer
		if the movie is available to be rented, then ask how many days would you like to rent the movie
		using the cost of that particular movie object, calculate the total cost
		if the balance of the account is sufficient, then deduct the cost from the balance and update the status of the movie
		else, say "sorry, you do not have enough money to rent movie X for Y days"*/

		//display menu
		//get the input from the user
		//based on the input, perform the action in the menu
		
		//display 4 choices
		switch (temp)
	  {
		case 1:	//1.) Rent Movie - see case 1 below
		{   
			cout << "Select a movie to rent";

			for (i = 0; i <= 9; i++)
			{
				cout << arraymovie[i].getname_of_movie();
				int movie_choice = 0;
				cin >> movie_choice;
					arraymovie[movie_choice].setis_the_movie_rented_or_not(1);
				cout << "Is this correct? Enter 'yes' or 'no'";
			}
			int movie_choice = 0;
			cin >> movie_choice;
			if ("yes")
				arraymovie[movie_choice].setis_the_movie_rented_or_not(1);

			else ("no");
			break;
			cout << "Thank you for renting " << arraymovie[i].getname_of_movie() << ", you have 24 hours to return the movie.";
			break;
		}



		case 2:	//2.) Return Movie - update the status of the movie being returned
		{
			for(i = 0; i <= 9; i++)
			//if(arraymovie[i] == false)
			break;
		}



		case 3:	//3.) Check Account - list which movies are being rented and display balance of account
		{
			cout << "User1";
			cout << "ID#: 12345";
			cout << "Current balance: $";

			break;
		}



		case 4:	//4.) Exit
		{
			break;
		}



		default: 
		{
			"Please select 1, 2, 3, or 4 as your command.";
			break;
		}
	  }
	}
	cin.get();
	cin.get();
}


This is my main file as I also have the header for movie and account as well as the .cpp files for them if needed
1
2
3
4
5
6
7
8
			for (i = 0; i <= 9; i++)
			{
				cout << arraymovie[i].getname_of_movie();
				int movie_choice = 0;
				cin >> movie_choice;
					arraymovie[movie_choice].setis_the_movie_rented_or_not(1);
				cout << "Is this correct? Enter 'yes' or 'no'";
			}

You did not have any cin statement to input "yes" or "no" for this prompt.

Edit : Can you show us the contents of "Movie.h"?
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <string>
#include <iomanip>

using namespace std;
#ifndef Movie_h
#define Movie_h

class movie {

private:

	string name_of_movie;
	int year_of_movie;
	string genre_of_movie;
	bool is_the_movie_rented_or_not;
	float cost_of_movie_to_rent_per_day;

public:
	movie();

	movie(string, int, string, bool, float);
	
	string getname_of_movie()const;
	int getyear_of_movie()const;
	string getgenre_of_movie()const;
	bool getis_the_movie_rented_or_not() const;
	float getcost_of_movie_to_rent_per_day()const;

	void setis_the_movie_rented_or_not(bool);
	
};
#endif // !Movie_h 
How about Movie.cpp too? We need to see it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "Movie.h"

movie::movie()
{
	name_of_movie = "";
	year_of_movie = 0;
	genre_of_movie = "";
	is_the_movie_rented_or_not = 0;
	cost_of_movie_to_rent_per_day = 0.0;
}
movie::movie(string newname, int newyear, string newgenre, bool newrented, float newcost)
{
	name_of_movie = newname;
	year_of_movie = newyear;
	genre_of_movie = newgenre;
	is_the_movie_rented_or_not = newrented;
	cost_of_movie_to_rent_per_day = newcost;
}
string movie::getname_of_movie()const {
	return name_of_movie;
}
int movie::getyear_of_movie()const {
	return year_of_movie;
}
string movie::getgenre_of_movie()const {
	return genre_of_movie;
}
bool movie::getis_the_movie_rented_or_not()const {
	return is_the_movie_rented_or_not;
}
float movie::getcost_of_movie_to_rent_per_day()const {
	return cost_of_movie_to_rent_per_day;
}
void movie::setis_the_movie_rented_or_not(bool newrented) {
	is_the_movie_rented_or_not = newrented;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "Account.h"

Account::Account()
{
	name = "";
	ID = 0.0;
	balance = 0.0;
}
Account::Account(string newname, double newID, double newbalance)
{
	name = newname;
	ID = newID;
	balance = newbalance;
}
string Account::getname()const{
	return name;
}
double Account::getID()const {
	return ID;
}
double Account::getbalance()const {
	return balance;
}
void Account::setbalance(double newbalance) {
	balance = newbalance;
}


Account header
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;
#ifndef Account_h
#define Account_h



class Account {

private:
	string name; //of account
	double ID; //of account
	double balance; //of account
	double newbalance;
public:
	Account();

	Account(string, double, double);
	string getname()const;
	double getID()const;
	double getbalance()const;

	void setbalance(double);
};
#endif // !Account_h 

Your naming convention is really verbose and unnecessary.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class movie {
// default access specifier is private
    string name;
    int year;
    string genre;
    bool is_rented;
    float daily_rent_cost;

public:
    movie();
    movie(string, int, string, bool, float);
    
    // accessors
    string get_name() const;
    int get_year() const;
    string get_genre() const;
    bool get_is_rented() const;
    float get_daily_rent_cost() const;

    // mutators
    void set_is_rented(bool); 
};


1
2
3
4
5
6
7
8
for (i = 0; i <= 9; i++)
{
    cout << i << ") " << arraymovie[i].get_name() << '\n';
    int movie_choice = 0;
    cin >> movie_choice;
    arraymovie[movie_choice].setis_the_movie_rented_or_not(1);
    cout << "Is this correct? Enter 'yes' or 'no'";
}

You would print the name of the movies first, each with a selection number(i). Then you would ask the user to input whichever movie, indicated by the selection number(i).
Next, you should check the validity of movie_choice, then add a confirmation prompt.
1
2
3
4
5
6
7
8
9
while( true ) {
    cout << "You've selected \"" + arraymovie[movie_choice] + "\"\n";

    string verify{};
    cout << "Is this correct? Enter 'yes' or 'no'";
    cin >> verify;

    if( verify == "yes" ) break;
}

Finally, set the selected movie to rented.
 
arraymovie[movie_choice].set_is_rented( true );


if I change the objects names I get errors

Woops! My bad. I updated the names above.
Last edited on
if I change the objects names I get errors
1
2
3
4
cout << "Select 1 to rent a movie \n";
cout << "Select 2 to return a movie \n";
cout << "Select 3 to view my account \n";
cout << "Select 4 to exit \n";

If you choose 1, you can rent some movies and lose your balance.
If you choose 2, you can return the movies you rent and get your entire money back.
If you choose 3, you can view your balance.
If you choose 4, you will exit the program.

Is it how things are supposed to work?

Yeah that's the idea except when a movie is returned the user doesn't get their money back.
Also if they haven't rented any movies and they enter 2, then I want it to display that they don't have any movies to return. It sounds like an if statement, but I don't know how I would code it.
Also if they haven't rented any movies and they enter 2, then I want it to display that they don't have any movies to return. It sounds like an if statement, but I don't know how I would code it.


Simply loop through arraymovie and check is_rented.
1
2
3
4
bool can_return{ false };
for( int i{}; i < num_movies; i++ )
    if( arraymove[i].get_is_rented( ) )
        can_return = true;
I'm having problems in my case statement. It's saying I have illegal use of '*'left operand has type float. Another is > or < has no conversion from float (__thiscallmovie:*)(void)const' to float and I'm getting pointer problems to use & in movie::get_daily_rent_cost:non-standard syntax I've never dealt with pointers so I'm not sure what to do.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
switch (temp)
	  {
		case 1:	//1.) Rent Movie - see case 1 below
		{   
			system("cls");
			cout << "Select a movie to rent\n";

			for (i = 0; i <= 9; i++)
			{	
				cout << i << ")" << arraymovie[i].get_name() << "\n";
				
				if (arraymovie[i].get_is_rented == false)
				{
				cout << arraymovie[i].get_name();
				cout << arraymovie[i].get_year();
				cout << arraymovie[i].get_genre();
				cout << arraymovie[i].get_daily_rent_cost();
				
				}
			}
			cout << "Choose a movie to rent corresponding to the numbers. \n Type 'b' to return to the main menu.";
			cin >> movie_choice;
			if (movie_choice == 'b')
			{
				break;
			}
			if (movie_choice != 'b')
			{
				cout << arraymovie[movie_choice].get_name();
				cout << "How many days would you like to rent?";
				cin >> days;
				newbalance = temp - days * arraymovie[movie_choice].get_daily_rent_cost;

				if (newbalance < arraymovie[movie_choice].get_daily_rent_cost)
				{
					cout << "Sorry not enough money!";
				}
				if (newbalance > arraymovie[movie_choice].get_daily_rent_cost)
				{
					arraymovie[movie_choice].set_is_rented(true);
					cout << "Your total is $" << arraymovie[movie_choice].get_daily_rent_cost * days;
					newaccount.setbalance(newbalance);
					cout << "Thank you for your purchase! You now have $" << newbalance;
				}
			}

				break;
				
			
	//		cout << "Thank you for renting " << arraymovie[i].getname_of_movie() << ", your total is" << arraymovie[i].getcost_of_movie_to_rent_per_day;
			break;
			//Account balance = Account.setbalance();
		}
arraymovie[movie_choice].get_daily_rent_cost
This is a function. You're missing the function call parentheses.
Oh of course! Thanks.

Help I accidentally clicked ctrl + f4 instead of ctrl + f5 now my main.cpp file is gone what do I do?!
Last edited on
Nevermind I got it back. Anyways how can I get my balance to be updated once a movie is rented because it subtracts the balance, but once I rent another movie it starts over at $100 (starting amount) also how can I prevent the same movie being rented assuming all movies only have 1 available?
Can anybody help me please
Topic archived. No new replies allowed.