Can't call struct function in main












1















So, for some reason, my code won't compile and I keep running into this error:




could not convert '(Movie*)(& myMovie)' from 'Movie*' to 'Movie'**




Not sure what does it mean when it says that, appreciate it if someone can tell me whats wrong with my code, also, new to structs so apologies for any stupid mistakes.



I want to output what the user entered when prompted for the movie details questions, but as I mentioned not working.



Thanks.
Here is my code :



#include <iostream>
#include <cstring>
#include <iomanip>
#include <climits>
#include <cstdlib>

using namespace std;

const int MAX = 256;
const int MAXNUM = 10;
const int MINNUM = 1;

typedef char Word[MAX];

//define a struct for a Movie
struct Movie{
Word title;
Word Director;
float length;
};


// prompts user for number between min and max, and returns valid input
int getIntInRange(int min, int max);



//prompts user for a positive float, and returns valid value
float getPositiveFloat();


//prompts user to enter all the values in a movie and returns the movie

//implement these two functions

Movie getMovieFromUser();
//outputs a single movie

void outputMovie(Movie m);



//describe program to user
void displayOverview();


int main(){

//output overview of program

//prompt user to enter their favourite movie

//use the getMovieFromUser() function to get the movie and store it in a variable

//output the movie using the outputMovie function


cout << endl;

Movie myMovie[MAXNUM];
getMovieFromUser(????);
outputMovie(????);


return 0;
}

Movie getMovieFromUser(){

Movie myMovie;
//prompt user to enter title, and save it
//prompt user to enter director and save it
//prompt user for length, and save it

Word buffer;
cout << "Please enter your favourite movie n";
cout << "Title: ";
cin.getline(buffer, MAX);
strcpy(m.title, buffer);
cout << "Director: ";
cin.getline(buffer, MAX);
strcpy(m.Director, buffer);
m.length = getPositiveFloat();


return myMovie;
}


void outputMovie(Movie m){
//output the contents of this movie
cout << "Title: " << m.title << endl;
cout << "Director: " << m.Director << endl;
cout << "Length (minutes): " << m.length << endl;
}









share|improve this question

























  • What's with the (????)? Also, why Movie getMovieFromUser(); if that function takes a Movie&?

    – David Schwartz
    Nov 24 '18 at 4:08













  • the ???? is what do I put here?

    – Laila Murish
    Nov 24 '18 at 4:09











  • Presumably what you "put here" is myMovie[0], since the variable is an array of Movie objects. I don't understand why you have a local unused copy in that function that is returned.

    – paddy
    Nov 24 '18 at 4:13











  • could not convert '(Movie*)(& myMovie)' from 'Movie*' to 'Movie'** If you do not know what this means, discussions about other stuff is sort of pointless. Point being: This is important!

    – Ted Lyngmo
    Nov 24 '18 at 4:20


















1















So, for some reason, my code won't compile and I keep running into this error:




could not convert '(Movie*)(& myMovie)' from 'Movie*' to 'Movie'**




Not sure what does it mean when it says that, appreciate it if someone can tell me whats wrong with my code, also, new to structs so apologies for any stupid mistakes.



I want to output what the user entered when prompted for the movie details questions, but as I mentioned not working.



Thanks.
Here is my code :



#include <iostream>
#include <cstring>
#include <iomanip>
#include <climits>
#include <cstdlib>

using namespace std;

const int MAX = 256;
const int MAXNUM = 10;
const int MINNUM = 1;

typedef char Word[MAX];

//define a struct for a Movie
struct Movie{
Word title;
Word Director;
float length;
};


// prompts user for number between min and max, and returns valid input
int getIntInRange(int min, int max);



//prompts user for a positive float, and returns valid value
float getPositiveFloat();


//prompts user to enter all the values in a movie and returns the movie

//implement these two functions

Movie getMovieFromUser();
//outputs a single movie

void outputMovie(Movie m);



//describe program to user
void displayOverview();


int main(){

//output overview of program

//prompt user to enter their favourite movie

//use the getMovieFromUser() function to get the movie and store it in a variable

//output the movie using the outputMovie function


cout << endl;

Movie myMovie[MAXNUM];
getMovieFromUser(????);
outputMovie(????);


return 0;
}

Movie getMovieFromUser(){

Movie myMovie;
//prompt user to enter title, and save it
//prompt user to enter director and save it
//prompt user for length, and save it

Word buffer;
cout << "Please enter your favourite movie n";
cout << "Title: ";
cin.getline(buffer, MAX);
strcpy(m.title, buffer);
cout << "Director: ";
cin.getline(buffer, MAX);
strcpy(m.Director, buffer);
m.length = getPositiveFloat();


return myMovie;
}


void outputMovie(Movie m){
//output the contents of this movie
cout << "Title: " << m.title << endl;
cout << "Director: " << m.Director << endl;
cout << "Length (minutes): " << m.length << endl;
}









share|improve this question

























  • What's with the (????)? Also, why Movie getMovieFromUser(); if that function takes a Movie&?

    – David Schwartz
    Nov 24 '18 at 4:08













  • the ???? is what do I put here?

    – Laila Murish
    Nov 24 '18 at 4:09











  • Presumably what you "put here" is myMovie[0], since the variable is an array of Movie objects. I don't understand why you have a local unused copy in that function that is returned.

    – paddy
    Nov 24 '18 at 4:13











  • could not convert '(Movie*)(& myMovie)' from 'Movie*' to 'Movie'** If you do not know what this means, discussions about other stuff is sort of pointless. Point being: This is important!

    – Ted Lyngmo
    Nov 24 '18 at 4:20
















1












1








1








So, for some reason, my code won't compile and I keep running into this error:




could not convert '(Movie*)(& myMovie)' from 'Movie*' to 'Movie'**




Not sure what does it mean when it says that, appreciate it if someone can tell me whats wrong with my code, also, new to structs so apologies for any stupid mistakes.



I want to output what the user entered when prompted for the movie details questions, but as I mentioned not working.



Thanks.
Here is my code :



#include <iostream>
#include <cstring>
#include <iomanip>
#include <climits>
#include <cstdlib>

using namespace std;

const int MAX = 256;
const int MAXNUM = 10;
const int MINNUM = 1;

typedef char Word[MAX];

//define a struct for a Movie
struct Movie{
Word title;
Word Director;
float length;
};


// prompts user for number between min and max, and returns valid input
int getIntInRange(int min, int max);



//prompts user for a positive float, and returns valid value
float getPositiveFloat();


//prompts user to enter all the values in a movie and returns the movie

//implement these two functions

Movie getMovieFromUser();
//outputs a single movie

void outputMovie(Movie m);



//describe program to user
void displayOverview();


int main(){

//output overview of program

//prompt user to enter their favourite movie

//use the getMovieFromUser() function to get the movie and store it in a variable

//output the movie using the outputMovie function


cout << endl;

Movie myMovie[MAXNUM];
getMovieFromUser(????);
outputMovie(????);


return 0;
}

Movie getMovieFromUser(){

Movie myMovie;
//prompt user to enter title, and save it
//prompt user to enter director and save it
//prompt user for length, and save it

Word buffer;
cout << "Please enter your favourite movie n";
cout << "Title: ";
cin.getline(buffer, MAX);
strcpy(m.title, buffer);
cout << "Director: ";
cin.getline(buffer, MAX);
strcpy(m.Director, buffer);
m.length = getPositiveFloat();


return myMovie;
}


void outputMovie(Movie m){
//output the contents of this movie
cout << "Title: " << m.title << endl;
cout << "Director: " << m.Director << endl;
cout << "Length (minutes): " << m.length << endl;
}









share|improve this question
















So, for some reason, my code won't compile and I keep running into this error:




could not convert '(Movie*)(& myMovie)' from 'Movie*' to 'Movie'**




Not sure what does it mean when it says that, appreciate it if someone can tell me whats wrong with my code, also, new to structs so apologies for any stupid mistakes.



I want to output what the user entered when prompted for the movie details questions, but as I mentioned not working.



Thanks.
Here is my code :



#include <iostream>
#include <cstring>
#include <iomanip>
#include <climits>
#include <cstdlib>

using namespace std;

const int MAX = 256;
const int MAXNUM = 10;
const int MINNUM = 1;

typedef char Word[MAX];

//define a struct for a Movie
struct Movie{
Word title;
Word Director;
float length;
};


// prompts user for number between min and max, and returns valid input
int getIntInRange(int min, int max);



//prompts user for a positive float, and returns valid value
float getPositiveFloat();


//prompts user to enter all the values in a movie and returns the movie

//implement these two functions

Movie getMovieFromUser();
//outputs a single movie

void outputMovie(Movie m);



//describe program to user
void displayOverview();


int main(){

//output overview of program

//prompt user to enter their favourite movie

//use the getMovieFromUser() function to get the movie and store it in a variable

//output the movie using the outputMovie function


cout << endl;

Movie myMovie[MAXNUM];
getMovieFromUser(????);
outputMovie(????);


return 0;
}

Movie getMovieFromUser(){

Movie myMovie;
//prompt user to enter title, and save it
//prompt user to enter director and save it
//prompt user for length, and save it

Word buffer;
cout << "Please enter your favourite movie n";
cout << "Title: ";
cin.getline(buffer, MAX);
strcpy(m.title, buffer);
cout << "Director: ";
cin.getline(buffer, MAX);
strcpy(m.Director, buffer);
m.length = getPositiveFloat();


return myMovie;
}


void outputMovie(Movie m){
//output the contents of this movie
cout << "Title: " << m.title << endl;
cout << "Director: " << m.Director << endl;
cout << "Length (minutes): " << m.length << endl;
}






c++ struct






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 4:20







Laila Murish

















asked Nov 24 '18 at 4:06









Laila MurishLaila Murish

296




296













  • What's with the (????)? Also, why Movie getMovieFromUser(); if that function takes a Movie&?

    – David Schwartz
    Nov 24 '18 at 4:08













  • the ???? is what do I put here?

    – Laila Murish
    Nov 24 '18 at 4:09











  • Presumably what you "put here" is myMovie[0], since the variable is an array of Movie objects. I don't understand why you have a local unused copy in that function that is returned.

    – paddy
    Nov 24 '18 at 4:13











  • could not convert '(Movie*)(& myMovie)' from 'Movie*' to 'Movie'** If you do not know what this means, discussions about other stuff is sort of pointless. Point being: This is important!

    – Ted Lyngmo
    Nov 24 '18 at 4:20





















  • What's with the (????)? Also, why Movie getMovieFromUser(); if that function takes a Movie&?

    – David Schwartz
    Nov 24 '18 at 4:08













  • the ???? is what do I put here?

    – Laila Murish
    Nov 24 '18 at 4:09











  • Presumably what you "put here" is myMovie[0], since the variable is an array of Movie objects. I don't understand why you have a local unused copy in that function that is returned.

    – paddy
    Nov 24 '18 at 4:13











  • could not convert '(Movie*)(& myMovie)' from 'Movie*' to 'Movie'** If you do not know what this means, discussions about other stuff is sort of pointless. Point being: This is important!

    – Ted Lyngmo
    Nov 24 '18 at 4:20



















What's with the (????)? Also, why Movie getMovieFromUser(); if that function takes a Movie&?

– David Schwartz
Nov 24 '18 at 4:08







What's with the (????)? Also, why Movie getMovieFromUser(); if that function takes a Movie&?

– David Schwartz
Nov 24 '18 at 4:08















the ???? is what do I put here?

– Laila Murish
Nov 24 '18 at 4:09





the ???? is what do I put here?

– Laila Murish
Nov 24 '18 at 4:09













Presumably what you "put here" is myMovie[0], since the variable is an array of Movie objects. I don't understand why you have a local unused copy in that function that is returned.

– paddy
Nov 24 '18 at 4:13





Presumably what you "put here" is myMovie[0], since the variable is an array of Movie objects. I don't understand why you have a local unused copy in that function that is returned.

– paddy
Nov 24 '18 at 4:13













could not convert '(Movie*)(& myMovie)' from 'Movie*' to 'Movie'** If you do not know what this means, discussions about other stuff is sort of pointless. Point being: This is important!

– Ted Lyngmo
Nov 24 '18 at 4:20







could not convert '(Movie*)(& myMovie)' from 'Movie*' to 'Movie'** If you do not know what this means, discussions about other stuff is sort of pointless. Point being: This is important!

– Ted Lyngmo
Nov 24 '18 at 4:20














1 Answer
1






active

oldest

votes


















3














Your code doesn't agree with itself. You have:



Movie getMovieFromUser();


But then later:



Movie getMovieFromUser(Movie &m){


The first seems to make more sense. A function called getMovieFromUser can either take a reference parameter that it fills in or return a value. Returning a value seems to make more sense. With that fix, this code should compile:



Movie myMovie[MAXNUM];
myMovie[0] = getMovieFromUser();
outputMovie(myMovie[0]);


You'll need to get rid of the Movie &m parameter in getMovieFromUser. Just create one locally (as you already do). I'd suggest calling it m rather than myMovie as it can create confusion to have two variables with the same name.



Putting that together:



Movie getMovieFromUser(){

Movie m;
//prompt user to enter title, and save it
//prompt user to enter director and save it
//prompt user for length, and save it

Word buffer;
cout << "Please enter your favourite movie n";
cout << "Title: ";
cin.getline(buffer, MAX);
strcpy(m.title, buffer);
cout << "Director: ";
cin.getline(buffer, MAX);
strcpy(m.Director, buffer);
m.length = getPositiveFloat();
return m;
}





share|improve this answer
























  • I am sorry, that was a mistake I left, but yes I get you now, thank you, I can't get my head around structs for some reason so thank you for guiding me.

    – Laila Murish
    Nov 24 '18 at 4:19











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53455059%2fcant-call-struct-function-in-main%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









3














Your code doesn't agree with itself. You have:



Movie getMovieFromUser();


But then later:



Movie getMovieFromUser(Movie &m){


The first seems to make more sense. A function called getMovieFromUser can either take a reference parameter that it fills in or return a value. Returning a value seems to make more sense. With that fix, this code should compile:



Movie myMovie[MAXNUM];
myMovie[0] = getMovieFromUser();
outputMovie(myMovie[0]);


You'll need to get rid of the Movie &m parameter in getMovieFromUser. Just create one locally (as you already do). I'd suggest calling it m rather than myMovie as it can create confusion to have two variables with the same name.



Putting that together:



Movie getMovieFromUser(){

Movie m;
//prompt user to enter title, and save it
//prompt user to enter director and save it
//prompt user for length, and save it

Word buffer;
cout << "Please enter your favourite movie n";
cout << "Title: ";
cin.getline(buffer, MAX);
strcpy(m.title, buffer);
cout << "Director: ";
cin.getline(buffer, MAX);
strcpy(m.Director, buffer);
m.length = getPositiveFloat();
return m;
}





share|improve this answer
























  • I am sorry, that was a mistake I left, but yes I get you now, thank you, I can't get my head around structs for some reason so thank you for guiding me.

    – Laila Murish
    Nov 24 '18 at 4:19
















3














Your code doesn't agree with itself. You have:



Movie getMovieFromUser();


But then later:



Movie getMovieFromUser(Movie &m){


The first seems to make more sense. A function called getMovieFromUser can either take a reference parameter that it fills in or return a value. Returning a value seems to make more sense. With that fix, this code should compile:



Movie myMovie[MAXNUM];
myMovie[0] = getMovieFromUser();
outputMovie(myMovie[0]);


You'll need to get rid of the Movie &m parameter in getMovieFromUser. Just create one locally (as you already do). I'd suggest calling it m rather than myMovie as it can create confusion to have two variables with the same name.



Putting that together:



Movie getMovieFromUser(){

Movie m;
//prompt user to enter title, and save it
//prompt user to enter director and save it
//prompt user for length, and save it

Word buffer;
cout << "Please enter your favourite movie n";
cout << "Title: ";
cin.getline(buffer, MAX);
strcpy(m.title, buffer);
cout << "Director: ";
cin.getline(buffer, MAX);
strcpy(m.Director, buffer);
m.length = getPositiveFloat();
return m;
}





share|improve this answer
























  • I am sorry, that was a mistake I left, but yes I get you now, thank you, I can't get my head around structs for some reason so thank you for guiding me.

    – Laila Murish
    Nov 24 '18 at 4:19














3












3








3







Your code doesn't agree with itself. You have:



Movie getMovieFromUser();


But then later:



Movie getMovieFromUser(Movie &m){


The first seems to make more sense. A function called getMovieFromUser can either take a reference parameter that it fills in or return a value. Returning a value seems to make more sense. With that fix, this code should compile:



Movie myMovie[MAXNUM];
myMovie[0] = getMovieFromUser();
outputMovie(myMovie[0]);


You'll need to get rid of the Movie &m parameter in getMovieFromUser. Just create one locally (as you already do). I'd suggest calling it m rather than myMovie as it can create confusion to have two variables with the same name.



Putting that together:



Movie getMovieFromUser(){

Movie m;
//prompt user to enter title, and save it
//prompt user to enter director and save it
//prompt user for length, and save it

Word buffer;
cout << "Please enter your favourite movie n";
cout << "Title: ";
cin.getline(buffer, MAX);
strcpy(m.title, buffer);
cout << "Director: ";
cin.getline(buffer, MAX);
strcpy(m.Director, buffer);
m.length = getPositiveFloat();
return m;
}





share|improve this answer













Your code doesn't agree with itself. You have:



Movie getMovieFromUser();


But then later:



Movie getMovieFromUser(Movie &m){


The first seems to make more sense. A function called getMovieFromUser can either take a reference parameter that it fills in or return a value. Returning a value seems to make more sense. With that fix, this code should compile:



Movie myMovie[MAXNUM];
myMovie[0] = getMovieFromUser();
outputMovie(myMovie[0]);


You'll need to get rid of the Movie &m parameter in getMovieFromUser. Just create one locally (as you already do). I'd suggest calling it m rather than myMovie as it can create confusion to have two variables with the same name.



Putting that together:



Movie getMovieFromUser(){

Movie m;
//prompt user to enter title, and save it
//prompt user to enter director and save it
//prompt user for length, and save it

Word buffer;
cout << "Please enter your favourite movie n";
cout << "Title: ";
cin.getline(buffer, MAX);
strcpy(m.title, buffer);
cout << "Director: ";
cin.getline(buffer, MAX);
strcpy(m.Director, buffer);
m.length = getPositiveFloat();
return m;
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 24 '18 at 4:13









David SchwartzDavid Schwartz

137k14144226




137k14144226













  • I am sorry, that was a mistake I left, but yes I get you now, thank you, I can't get my head around structs for some reason so thank you for guiding me.

    – Laila Murish
    Nov 24 '18 at 4:19



















  • I am sorry, that was a mistake I left, but yes I get you now, thank you, I can't get my head around structs for some reason so thank you for guiding me.

    – Laila Murish
    Nov 24 '18 at 4:19

















I am sorry, that was a mistake I left, but yes I get you now, thank you, I can't get my head around structs for some reason so thank you for guiding me.

– Laila Murish
Nov 24 '18 at 4:19





I am sorry, that was a mistake I left, but yes I get you now, thank you, I can't get my head around structs for some reason so thank you for guiding me.

– Laila Murish
Nov 24 '18 at 4:19




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53455059%2fcant-call-struct-function-in-main%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Tonle Sap (See)

I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

Guatemaltekische Davis-Cup-Mannschaft