CODE
#include<iostream.h>
#include<fstream.h>
#include<cstdio.h>
#include<cstring.h>
struct customer
{
name[1000];
movies[1000];
};
void DisplayMenu(); //Functions
void CommandClose();
int main()
{
movie mov;
customer cust;
char input[20], line[30];
ifstream customerfile("customer.dat"); //Open the files
ifstream moviefile("movie.dat");
DisplayMenu();
if(!customerfile||!moviefile)
{ //If no file exit the program..
cout << "Error reading files";
return 0;
}
else
{
cout << "The file customer.dat contains" << endl;
while(customerfile.getline(line, 29)) //Gets the line
{
if( sscanf(line, "%s %ld %d ", &cust.name, &cust.phone_number, &cust.movies) == 3) //scans for name phone number and movies
cout < <cust.name <<" "<< cust.phone_number <<" "<< cust.movies << endl;
else { //If there was an error it quits
cout << "Error in file format" << endl;
return 0;
}
}
cout << "The file movie.dat contains" << endl;
while(moviefile.getline(line, 29)) //Gets the line and scans for movie title and the number next to it
{
if(sscanfile(line, "%s %d", &mov.title, &mov.number) == 2)
{
cout <<mov.title <<" "<< mov.number <<" "<< endl;
}
if ( strcmp( input, mov.title ) == 0 )
{
cout << input <<" Found in file with availabililty: " << mov.number;
}
}
}
}
getchar();
CloseCommand();
return 0;
}
void DisplayMenu() //Displays the introduction to program
{
cout << "Welcome to the inventory and customers computer.\n\nThere are 4 main commands that can be inputed: \n\n1)Setup 2)Sale 3)Inventory 4)Close\n\n";
cout << "What would you like to do? Please enter the corresponding number\n";
}
void CloseCommand() //Sends message for user to close program
{
cout << "Thank your for using Movie Rental Program\n";
}
}
This post has been edited by ChaNgeD: 7 Dec, 2005 - 08:17 AM