Now help me with this. Tell me where I am going wrong. I am making a simple movie-guessing game.
With check_movie()
I am trying to update the movie from its temporary array after every guess.
I am getting the following error: incompatible types in assignment of char*
to char[100]
Its something with the check_movie()
Where am I going wrong?
I am trying to return an array from any function for the first time. I am just a beginner. I googled a lot about returning arrays but the examples were out of my brain's reach.
#include<iostream.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
#include<conio.h>
void display_movie(char movie_temp[], int);
void display_life(int);
int win_player2(char movie_temp[]);
int check_life(char movie[], char, int);
char *check_movie(char movie[], char movie_temp[], char ch); //not sure about this func.
char *check_movie(char movie[], char movie_temp[], char ch)
{
for(int i=0 ; movie[i]!='\0' ; i++)
{
if(movie[i]==ch)
movie_temp[i]=movie[i];
}
return movie_temp;
}
void display_movie(char movie_temp[], int len)
{
for(int i=0 ; i<len ; i++)
cout<<movie_temp[i];
}
void display_life(int life)
{
for(int i=0 ; i<=life ; i++)
cout<<"\3";
}
int check_life(char movie[], char ch, int life)
{
int count1=0;
for(int i=0 ; movie[i]!='\0' ; i++)
{
if(movie[i]==ch)
count1++;
}
if(count1==0)
return --life;
else
return life;
}
int win_player2(char movie_temp[])
{
int count=0;
for(int i=0 ; movie_temp[i]!='\0' ; i++)
{
if(movie_temp[i]=='_')
count++;
}
if(count==0)
return 0;
else
return 1;
}
int main()
{
char movie[100], movie_temp[100], ch;
cout<<"Enter the movie: ";
cin.getline(movie,100);
int len= strlen(movie);
system("cls");
for(int i=0 ; movie[i]!='\0' ; i++)
{
if(movie[i]=='a' || movie[i]=='e' || movie[i]=='i' || movie[i]=='o' ||
movie[i]=='u' || movie[i]==' ')
movie_temp[i]= movie[i];
else
movie_temp[i]='_';
}
int life=9;
cout<<"\nLives left: ";
display_life(life);
while(life!=0 || win_player2(movie_temp)!=0)
{
cout<<"\n";
display_movie(movie_temp, len);
cout<<"\nEnter your guess: ";
cin>>ch;
life=check_life(movie, ch, life); //Here I update life
//Updates life after every guess.
movie_temp=check_movie(movie, movie_temp, ch);
/*This part is getting me errors. I am trying to update movie_temp after every
guess.*/
cout<<"\n\nLives left: ";
display_life(life);
}
getch();
return 0;
}