I'm writing this program that basically interprets the rottentomatoes website. I am however having a problem declaring if it is rotten or fresh according to the rating the user enters.
I'm outputting it here:
1 2 3 4 5 6 7 8 9 10 11 12 13
void PrintAll(const string titles[], constint ratings[], int count)
{
WriteLine('=', 50);
cout << "PRINT ALL" << endl;
WriteLine('-', 50);
for(int i = 0; i < count; i++)
{
cout << setw(37) << left << titles[i]
<< setw(2) << left << ratings[i] << setw(5) << left << "%"
<< setw(4) << right << RatingToString(ratings, count) << endl;
}
}
==================================================
MENU
1. Add Movie
2. Print All
3. Exit
--------------------------------------------------
Enter 1-3 : 1
Title : Hitch
Rating : 90
==================================================
MENU
--------------------------------------------------
1. Add Movie
2. Print All
3. Exit
--------------------------------------------------
Enter 1-3 : 2
==================================================
PRINT ALL
--------------------------------------------------
Hitch 90% FRESH
==================================================
MENU
--------------------------------------------------
1. Add Movie
2. Print All
3. Exit
--------------------------------------------------
Enter 1-3 : 1
Title : The Hulk
Rating : 50
==================================================
MENU
--------------------------------------------------
1. Add Movie
2. Print All
3. Exit
--------------------------------------------------
Enter 1-3 : 2
==================================================
PRINT ALL
--------------------------------------------------
Hitch 90% ROTTEN
The Hulk 50% ROTTEN
==================================================
MENU
--------------------------------------------------
1. Add Movie
2. Print All
3. Exit
--------------------------------------------------
Enter 1-3 : 3
My condition works when there is only one movie, but when I add more, it gives it the new movies "ROTTEN" or "FRESH" rank. I don't know if this makes sense and if you guys know of a way to fix this? Thank you.
The string 'rank' is only declared once and is overwritten by each iteration of your loop. This means that the function returns the result of the last iteration (ratings[count-1]).
Try to adjust your function prototype like this:
string RatingToString(int rating)
(of course you need to adjust the function body as well (remove the loop))
and call it like this: