The movieid2 and movieid1 values are overwritten at each cycle, so why do write to them at line 11,12:
1 2
|
movieid2==bestmovie;
movieid1=userchoice;
| |
The == is a test, so I guess a typo.
You can not compare movie ids with rating percentages. It's like comparing apples to oranges, so this line makes no sense:
if (bestmovie == highpercent)
Constructions like:
1 2 3
|
if (condition)
statement1;
statement2;
| |
make the action of the first statement dependent on the result from the test, but the second statement is not affected by the condition. In fact the second statement is not part of the if in any way. To make both statements part of the if, you need to use:
1 2 3 4 5
|
if (condition)
{
statement1;
statement2;
}
| |
Here is what you ought to have done:
1 2 3 4 5 6 7 8
|
while (infile >> movieid1 >> movieid2 >> percent)
{
if ((userchoice == movieid1) && (percent > highpercent))
{
highpercent = percent; // value of Max = value of X
bestmovie = movieid2; // data of Max = data of X
}
}
| |
If you look at the pseudocode, and you make the following association you will see that it matches:
- "value of X" is percent
- "value of Max" is highpercent
- "data of X" is movieid2
- "data of Max" is bestmovie
Also, in pseudocode, conventionally indentation designates the block structure, but I will make it more explicit:
value of Max = -1
data of Max = whatever
For each element X in collection
If value of X > value of Max
value of Max = value of X
data of Max = data of X
End If
End For |
Regards