I have this code that has a couple of errors. I just need help on figuring out w
ID: 3686593 • Letter: I
Question
I have this code that has a couple of errors. I just need help on figuring out what they are.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main (){
int reviews[][6] ={{3,1,5,2,1,5},{4,2,1,4,2,4},{3,1,2,4,4,1},{5,1,4,2,4,2}};
int user_rate[] = new user_rate[6];
for(int i=0;i<6;i++)
user_rate[i]=0;
int mov=1;
while(true)
{
cout <<("Enter a movie to rate (100-105). Enter 0 to exit and get recommendations.");
cin >> mov;
if(mov==0)break;
cout <<("Enter rating 1-5 for the movie");
cin >> user_rate[mov%10];
}
double min_car=1000,temp=0;
int q=0;
for(int i=0;i<4;i++)
{
for(int j=0;j<6;j++)
{
if(user_rate[j]!=0)
{
temp=temp+((reviews[i][j]-user_rate[j])*(reviews[i][j]-user_rate[j]));
}
}
temp=sqrt(temp);
if(temp<min_car)
{
min_car=temp;
q=i;
}
temp=0;
}
cout<<("closest reviewer is "+q);
cout<<("Reviews of the movies by the same reviewer that you have not seen");
for(int i=0;i<6;i++)
{
if(user_rate[i]==0){
cout << "movie " << + << " " <<(100+i)<< + << " "<< + << reviews[q][i] << endl;
}
return 0;
}
}
Explanation / Answer
Hi I have fixed all erors. Please test it.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main (){
int reviews[][6] ={{3,1,5,2,1,5},{4,2,1,4,2,4},{3,1,2,4,4,1},{5,1,4,2,4,2}};
int user_rate[6];
for(int i=0;i<6;i++)
user_rate[i]=0;
int mov=1;
while(true)
{
cout <<("Enter a movie to rate (100-105). Enter 0 to exit and get recommendations.");
cin >> mov;
if(mov==0)break;
cout <<("Enter rating 1-5 for the movie");
cin >> user_rate[mov%10];
}
double min_car=1000,temp=0;
int q=0;
for(int i=0;i<4;i++)
{
for(int j=0;j<6;j++)
{
if(user_rate[j]!=0)
{
temp=temp+((reviews[i][j]-user_rate[j])*(reviews[i][j]-user_rate[j]));
}
}
temp=sqrt(temp);
if(temp<min_car)
{
min_car=temp;
q=i;
}
temp=0;
}
cout<<("closest reviewer is "+q);
cout<<("Reviews of the movies by the same reviewer that you have not seen");
for(int i=0;i<6;i++)
{
if(user_rate[i]==0){
cout << "movie "<< " " <<(100+i)<< " "<< reviews[q][i] << endl;
}
return 0;
}
}