I am working on booking system and have added an if - else statement in my setRating function to compare user input to make sure invalid input is not entered. To best explain il show snippets of my code. To note no errors are coming up but upon testing it is only using the default value.
in my class. cpp file i have
constructor
book::Book(unsigned int iD, string title, string genre, string rating
:bookId(iD), bookTitle(title), bookGenre(genre), bookRating(rating)
{
//
setRating(rating);
setGenre(genre);
}
void Movie::setRating(string rating) {
// @param if rating is = to U or PG or 12 or 12A or 15 or 18 set rating
// if not set to to NA, condition to not probit invalid entry
if (rating == "U" || rating == "PG" || rating == "12" || rating == "12-A" || rating == "15" || rating == "18" || rating == "NR")
{
bookRating = rating;
}
else
bookRating = "NR";
}
string Book::getRating() {
return bookRating;
}
i used the above code so that the variable rating would have to be passed through setRating to compare. In my main class i have a fillvector function that asks for user input to fill the variables than then be used to create the object .
The code runs fine but when "Dog " for example and incorrect input is entered it changes it to NA like id hoped, but when a correct input is entered it still changes it to NA. I know this is a long post and i would appreciate any help given as i have tried numerous of things and nothing has worked. Any ideas would help it has me stumped. The above code is a representation of my code with a change of variable names only.
I don't see anything obviously wrong with the code. Post an example where the Book constructor is called with various values.
Also, please use code tags!