Writing a program to get the average of 2 scores on a movie. I'm trying to make it so if you input a number less than 0 or greater than 100 it will display "Invalid rating"
When I run it, the program will end after the first "if" statement no matter what number I input
int main()
{
//Get the name of the movie (The Incredibles)
string movie = "";
cout << "What is the name of the movie?: \n";
getline(cin, movie);
//Get the Metascore 0 < X > 100
int metascore = 0;
cout << "What is the Metascore rating for " << movie << "?\n";
cin >> metascore;
if (metascore < 0 && metascore > 100);
{
cout << "Invalid Metascore rating, program will end.\n";
return 0;
}
//Get the Tomatometer 0 < X > 100
int tomatometer = 0;
cout << "What is the Tomatometer rating for " << movie << "?\n";
cin >> tomatometer;
if (tomatometer < 0 && tomatometer > 100);
{
cout << "Invalid Tomatometer rating, program will end.\n";
return 0;
}
This is checking to see if the score is both below zero and above 100. It can't be both at the same time, so this will always be false. Try the logical OR operator || instead of the logical AND &&. (same on the tomatometer if code)
if (metascore < 0 && metascore > 100);
There are a few problems with this.
1) It should be || not &&. How can it be less than 0 and greater than 100 at the same time?
2) The semi-colon at the end should be removed.
Also on line 24 if (tomatometer < 0 && tomatometer > 100); you should remove the semi-colon at the end.