elninio
August 6th, 2007, 04:41 AM
#include <iostream>
#include <string>
using namespace std;
struct movies{
string title;
int year;
} movie[max];
void listmovies(int& max){
int i=0;
while (i<max){
cout<<movie[i]->title<<" ("<<movie[i]->year<<")\n";
i++;
}
}
void entermovies(){
movie = new (nothrow) int[count];
for (int i=0;movie[i]==0;i++){
cout << "Error: memory could not be allocated";
system("pause");
}
// movies * pmovie;
// pmovie = &p[m];
cout<<"Enter the name of a movie: ";
cin>>movie[count]->title;
cout<<"Enter that movie's year: ";
cin>>movie[count]->year;
cout<<"\n\n You have entered: \n"<< movie[count]->title<<" ("<<movie[count]->year<<")\n\n";
count++;
cout<<"Would you like to enter another movie (m) or view the list (l) or exit (e)? \n";
int input;
cin>>input;
switch (input){
case 'm':
entermovies();
case 'l':
listmovies();
case 'e':
return 0;
}
}
int main(){
string * p;
int max = 0, count = 0;
movies * movie[m];
system("TITLE Movie Database");
// system("CLS"); clears the screen
cout<<"Movie Database \n\n";
entermovies();
system("pause");
return 0;
}
its supposed to store movies that are ented in the program (title and year), and allocates memory accordingly, everytime the user wants to imput a new movie
here is the devcpp log:
Compiler: Default compiler
Executing g++.exe...
g++.exe "D:\c++ programming\moviesdatabasepointers.cpp" -o "D:\c++ programming\moviesdatabasepointers.exe" -I"lib\gcc\mingw32\3.4.2\include" -I"include\c++\3.4.2\backward" -I"include\c++\3.4.2\mingw32" -I"include\c++\3.4.2" -I"include" -L"lib"
D:\c++ programming\moviesdatabasepointers.cpp:9: error: size of array `movie' has non-integral type `<unknown type>'
D:\c++ programming\moviesdatabasepointers.cpp: In function `void listmovies(int&)':
D:\c++ programming\moviesdatabasepointers.cpp:14: error: base operand of `->' has non-pointer type `movies'
D:\c++ programming\moviesdatabasepointers.cpp:14: error: base operand of `->' has non-pointer type `movies'
D:\c++ programming\moviesdatabasepointers.cpp: In function `void entermovies()':
D:\c++ programming\moviesdatabasepointers.cpp:20: error: expression in new-declarator must have integral or enumeration type
D:\c++ programming\moviesdatabasepointers.cpp:21: error: no match for 'operator==' in 'movie[i] == 0'
D:\c++ programming\moviesdatabasepointers.cpp:28: error: invalid types `movies[1][<unknown type>]' for array subscript
D:\c++ programming\moviesdatabasepointers.cpp:30: error: invalid types `movies[1][<unknown type>]' for array subscript
D:\c++ programming\moviesdatabasepointers.cpp:31: error: invalid types `movies[1][<unknown type>]' for array subscript
D:\c++ programming\moviesdatabasepointers.cpp:31: error: invalid types `movies[1][<unknown type>]' for array subscript
D:\c++ programming\moviesdatabasepointers.cpp:32: error: no post-increment operator for type
D:\c++ programming\moviesdatabasepointers.cpp:11: error: too few arguments to function `void listmovies(int&)'
D:\c++ programming\moviesdatabasepointers.cpp:40: error: at this point in file
D:\c++ programming\moviesdatabasepointers.cpp:42: error: return-statement with a value, in function returning 'void'
D:\c++ programming\moviesdatabasepointers.cpp: In function `int main()':
D:\c++ programming\moviesdatabasepointers.cpp:49: error: `m' undeclared (first use this function)
D:\c++ programming\moviesdatabasepointers.cpp:49: error: (Each undeclared identifier is reported only once for each function it appears in.)
im mainly having trouble with the 'undeclared's. I think if i knew exactly how pointers work i would be able to fix most of this mess up, yes * is value pointed by and & is address of, but im still clueless when to use which and how :(
offer me some advice please!
#include <string>
using namespace std;
struct movies{
string title;
int year;
} movie[max];
void listmovies(int& max){
int i=0;
while (i<max){
cout<<movie[i]->title<<" ("<<movie[i]->year<<")\n";
i++;
}
}
void entermovies(){
movie = new (nothrow) int[count];
for (int i=0;movie[i]==0;i++){
cout << "Error: memory could not be allocated";
system("pause");
}
// movies * pmovie;
// pmovie = &p[m];
cout<<"Enter the name of a movie: ";
cin>>movie[count]->title;
cout<<"Enter that movie's year: ";
cin>>movie[count]->year;
cout<<"\n\n You have entered: \n"<< movie[count]->title<<" ("<<movie[count]->year<<")\n\n";
count++;
cout<<"Would you like to enter another movie (m) or view the list (l) or exit (e)? \n";
int input;
cin>>input;
switch (input){
case 'm':
entermovies();
case 'l':
listmovies();
case 'e':
return 0;
}
}
int main(){
string * p;
int max = 0, count = 0;
movies * movie[m];
system("TITLE Movie Database");
// system("CLS"); clears the screen
cout<<"Movie Database \n\n";
entermovies();
system("pause");
return 0;
}
its supposed to store movies that are ented in the program (title and year), and allocates memory accordingly, everytime the user wants to imput a new movie
here is the devcpp log:
Compiler: Default compiler
Executing g++.exe...
g++.exe "D:\c++ programming\moviesdatabasepointers.cpp" -o "D:\c++ programming\moviesdatabasepointers.exe" -I"lib\gcc\mingw32\3.4.2\include" -I"include\c++\3.4.2\backward" -I"include\c++\3.4.2\mingw32" -I"include\c++\3.4.2" -I"include" -L"lib"
D:\c++ programming\moviesdatabasepointers.cpp:9: error: size of array `movie' has non-integral type `<unknown type>'
D:\c++ programming\moviesdatabasepointers.cpp: In function `void listmovies(int&)':
D:\c++ programming\moviesdatabasepointers.cpp:14: error: base operand of `->' has non-pointer type `movies'
D:\c++ programming\moviesdatabasepointers.cpp:14: error: base operand of `->' has non-pointer type `movies'
D:\c++ programming\moviesdatabasepointers.cpp: In function `void entermovies()':
D:\c++ programming\moviesdatabasepointers.cpp:20: error: expression in new-declarator must have integral or enumeration type
D:\c++ programming\moviesdatabasepointers.cpp:21: error: no match for 'operator==' in 'movie[i] == 0'
D:\c++ programming\moviesdatabasepointers.cpp:28: error: invalid types `movies[1][<unknown type>]' for array subscript
D:\c++ programming\moviesdatabasepointers.cpp:30: error: invalid types `movies[1][<unknown type>]' for array subscript
D:\c++ programming\moviesdatabasepointers.cpp:31: error: invalid types `movies[1][<unknown type>]' for array subscript
D:\c++ programming\moviesdatabasepointers.cpp:31: error: invalid types `movies[1][<unknown type>]' for array subscript
D:\c++ programming\moviesdatabasepointers.cpp:32: error: no post-increment operator for type
D:\c++ programming\moviesdatabasepointers.cpp:11: error: too few arguments to function `void listmovies(int&)'
D:\c++ programming\moviesdatabasepointers.cpp:40: error: at this point in file
D:\c++ programming\moviesdatabasepointers.cpp:42: error: return-statement with a value, in function returning 'void'
D:\c++ programming\moviesdatabasepointers.cpp: In function `int main()':
D:\c++ programming\moviesdatabasepointers.cpp:49: error: `m' undeclared (first use this function)
D:\c++ programming\moviesdatabasepointers.cpp:49: error: (Each undeclared identifier is reported only once for each function it appears in.)
im mainly having trouble with the 'undeclared's. I think if i knew exactly how pointers work i would be able to fix most of this mess up, yes * is value pointed by and & is address of, but im still clueless when to use which and how :(
offer me some advice please!