Can someone tell me what I am doing wrong with this code as to why it will not c
ID: 3646585 • Letter: C
Question
Can someone tell me what I am doing wrong with this code as to why it will not compile?#include< iostream >
using namespace std;
//Structure
struct MovieData
{
char Title[35];
char Director[25];
int YearReleased;
int RunningTime;
};
//Functions
void ShowData (MovieData);
void main()
{
//MovieData Variable
MovieData movie1;
//movie1 data and title
cout << "Enter Movie Title";
cin.getline(movie1.Title, 35);
//Director
cout << "Enter Director Name: ";
cin.getline (movie1.Director, 25);
//Year Released
cout << "Enter Year Released: ";
cin >> movie1.YearReleased;
//Running Time
cout << "Enter Running Time (in minutes): ";
cin >> movie1.RunningTime;
//Declare variable to MovieData
MovieData movie2 = {"ET", "Steven Spielburg", 1982, 180};
//Function Call MovieData1
ShowData(movie1);
//Function Call MovieData2
ShowData(movie2);
system("pause");
}
void ShowData(MovieData p)
{
//Display
cout << "Movie Title: " <<p.Title<<endl;
cout << "Director: " << p.Director << endl;
cout << "Year Released: " << p.YearReleased << endl;
cout << "Runing Time: " << p.RunningTime << endl;
}
Explanation / Answer
your main method must return int value and header file must be included with no spaces between the angular brackets. Here's the perfect code,
#include<iostream.h>
using namespace std;
//Structure
struct MovieData
{
char Title[35];
char Director[25];
int YearReleased;
int RunningTime;
};
//Functions
void ShowData (MovieData);
int main()
{
//MovieData Variable
MovieData movie1;
//movie1 data and title
cout << "Enter Movie Title";
cin.getline(movie1.Title, 35);
//Director
cout << "Enter Director Name: ";
cin.getline (movie1.Director, 25);
//Year Released
cout << "Enter Year Released: ";
cin >> movie1.YearReleased;
//Running Time
cout << "Enter Running Time (in minutes): ";
cin >> movie1.RunningTime;
//Declare variable to MovieData
MovieData movie2 = {"ET", "Steven Spielburg", 1982, 180};
//Function Call MovieData1
ShowData(movie1);
//Function Call MovieData2
ShowData(movie2);
system("pause");
return 0;
}
void ShowData(MovieData p)
{
//Display
cout << "Movie Title: " <<p.Title<<endl;
cout << "Director: " << p.Director << endl;
cout << "Year Released: " << p.YearReleased << endl;
cout << "Runing Time: " << p.RunningTime << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.