//This is the main file

#include<iostream>
#include<fstream>
#include<string>
#include "Books.h"
#include"account.h"

using namespace std;

int main()

	

{
	cout << "\tWelcome\t" <<endl;
    cout << "1-Login" <<endl;
    cout << "2-Register" <<endl;
    cout << "3-exit" <<endl;

    cout << "Please enter a choice: ";
    cin >> choice;


    switch (choice){

		case 1:
				system ("cls");
				cout << "Please enter Username:\t";
				cin >> username;
				cout<<"Password: ";
				cin>>password;

				accounts.open ("accounts.txt");
						 {
						getline(accounts,data);
						 }
				passwords.open ("passwords.txt");
				{
					getline(passwords,data);
				}
		
					accounts.close();
					passwords.close();
					
					
				if (data.compare(username)==0,data.compare(password)==0)
				cout << "Welcome back "<< username << " to our private library" <<endl;
    
				else
				cout << "Sorry, invalid login information" <<endl;
					break;
		
		   case 2:
			   cout << "Please create new username:  ";
			   cin >> newAcc;
			   cout<<"Create new password: ";
			   cin >> newpassword;
				regAcc.open ("accounts.txt");
				regpass.open ("passwords.txt");
				regAcc << newAcc;
				regpass<<newpassword;
				regAcc.close();
				regpass.close();

				system("cls");
				cout<<"_______________________________________________________________"<<endl;
				cout << "Congratulations "<< newAcc <<" your account has been succesfully created.\t" <<endl;
				cout<<"_______________________________________________________________"<<endl;
	cout<<" "<<endl;
	cout << "Please enter your new login information "<<endl;
	cout<<"Username:";
	cin>>username;
	cout<<" "<<endl;
	cout<<"Password: ";
	cin>>password;
	
				accounts.open ("accounts.txt");
						 {
						getline(accounts,data);
						 }
				passwords.open ("passwords.txt");
				{
					getline(passwords,data);
				}
		
					accounts.close();
					passwords.close();

	if (data.compare(username)==0,data.compare(password)==0)

    cout << "Welcome "<< username << " now you have access to our private library" <<endl;
	else
		 
                       cout << "Sorry, invalid login information!!" <<endl;
					 break;
               
			  
		   case 3:
			   cout<<"Goodbye!!!"<<endl;
			   exit(1);
				 break;


		   default:
				
			   cout << "Sorry, invalid input" <<endl;
			 
}

	if (data.compare(username)!=0,data.compare(password)!=0)

    exit(1);
	else
		 
                  

	//if(choice==1 || 2)
	//	exit(1);
	//
	//else
		
		/*cout<<"Welcome to our library"<<endl;

		cout<<"Press 1 to continue or 2 to exit"<<endl;
		cout<<"Choice: ";*/
//		cin>>choice2;
//if (choice2==2);
//	exit(1);
//	else	(choice==1);

	

	
//system ("pause");
//return 0;
//}





	ifstream inFile;
	inFile.open("Bookdata.txt");
	string Title[3];
	string Author[3];
	int ISBN[3];
	double Price[3];
	int count=0;

	while (!inFile.eof())
	{
		inFile>>Title[count];
		inFile>>Author [count];
		inFile>>ISBN [count];
		inFile>>Price [count];
		count++;

	}
	Book Books[3];
	for (int x=0; x<3; x++)
	{
		Books [x].Setup (Title [x], Author[x], ISBN [x], Price [x]);


	}
	
	int num;
	cout<<"Please enter an ISBN number to search for"<<endl;
	cin>>num;
	int found=-1;
	for (int x=0; x<3; x++)
	{
		if (Books[x].ISBNSearch(num)== 1)
			found = x;


	}
	if (found != -1)
		cout<<"The book title is: "<<Books[found].GetTitle()<<endl;
	inFile.close();

	if (found != -1)
//		cout<<"The Author is: "<<Books[found].Setup()<<endl;
	inFile.close();
	
	
	system("pause");
	return 0;
}

//This is account.h

#include <iostream>
#include <fstream>
#include <string>
#include"Books.h"
using namespace std;

	ifstream accounts;
	ifstream passwords;
	string getcontent;
    string username;
	string password;
    string data;	
    int choice;
	int choice2;
	ofstream regAcc;
	ofstream regpass;
    string newAcc;
	string newpassword;

//this is Books.h

#include<string>
#ifndef Books_H
#define Books_H
using namespace std;

class Book
{

private:
string Title;
string Author;
int ISBN;
double Price;


public:
	Book(){} //does nothing : constructor
	Book (string title, string author, int isbn, double price){Title=title; Author=author; ISBN=isbn; Price=price;}//constructor
	void Setup(string, string, int, double);//acepts string name and author. int price. double price
	int ISBNSearch(int);
	string GetTitle();

	

};


#endif

//this is Books.cpp

#include"Books.h"

void Book::Setup(string title, string author, int isbn, double price)//declares book
{
	Title=title;
	Author=author; 
	ISBN=isbn; 
	Price=price;
}
int Book::ISBNSearch(int num)
{
	if (num == ISBN)
		return 1;
	else
		return 0;
}
string Book::GetTitle()
{
	return Title;
}

Please use code tags for code, and what are the errors you get?

this are the errors i get:

1>------ Build started: Project: Final Project, Configuration: Debug Win32 ------
1>Build started 4/25/2011 8:18:34 AM.
1>InitializeBuildStatus:
1> Creating "Debug\Final Project.unsuccessfulbuild" because "AlwaysCreate" was specified.
1>ClCompile:
1> main.cpp
1>c:\users\junior\documents\visual studio 2010\projects\final project\final project\main.cpp(142): error C2065: 'inFile' : undeclared identifier
1>c:\users\junior\documents\visual studio 2010\projects\final project\final project\main.cpp(142): error C2228: left of '.open' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\junior\documents\visual studio 2010\projects\final project\final project\main.cpp(149): error C2065: 'inFile' : undeclared identifier
1>c:\users\junior\documents\visual studio 2010\projects\final project\final project\main.cpp(149): error C2228: left of '.eof' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\junior\documents\visual studio 2010\projects\final project\final project\main.cpp(149): fatal error C1903: unable to recover from previous error(s); stopping compilation
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.00
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


it has something to do with the second part of the code which is the book inventory part. somethin about the inFile.open("Bookdata.txt"); and its definition. i think im right but idk whats wrong with it

This is just a hunch but try including fstream.h instead of frstream
Also can you make a sample code to just read data from a file as most of your errors seems related to file handling options

i already did but no luck. any other suggestions?

Did the sample code for reading files compile without any errors ?

Try to compile and run this:

#include <fstream>
#include <iostream>
#include <string>

using std::cout;
using std::endl;
using std::ifstream;
using std::ofstream;

char const * const fileName = "testFile.txt";

int main() {
  cout << "This is a file read/write test app...\n" << endl;

  { //open section 1
    ofstream outFile(fileName, std::ios::out | std::ios::trunc);
    outFile << "This is a test output file..." << endl;
    outFile.close();
  } //close section 1

  { //open section 2
    ifstream inFile1(fileName, std::ios::in);
    std::string data1;
    while (inFile1 >> data1) {
      cout << data1 << " ";
    }
    if (!inFile1.good()) {
      inFile1.clear();
    }
    inFile1.close();
  } //close section 2

  cout << "\n\n";

  { //open section 3
    ifstream inFile2(fileName, std::ios::in);
    std::string data2;
    std::getline(inFile2, data2);
    cout << data2 << endl;
    inFile2.close();
  } //close section 3

  return 0;
}

It creates an output file called "testFile.txt" that contains the string "This is a test output file...". (I thought it would be a more effective test than trying to attach a "seed" file to the post.)

You should get this for output:

This is a file read/write test app...

This is a test output file...

This is a test output file...

I tested this on VS2008 with no problems. If this doesn't compile, there is probably a problem with your include path(s)/file(s).

If this compiles and runs correctly, compare and contrast it with your code to see where you may have messed up.

I'm betting though that the problem has something to do with the else statement on Line 112 of your main. The compiler error is flagging Lines 142 and 143, which are the first non-comment lines of code after it. More than likely it doesn't see the identifier "inFile" because it's the only statement attached to the else, but the subsequent lines (which aren't attached to the else) rely on it. You really should add some curly-braces to define the blocking of your code better.

so how do i fix my if statement? lines 109-113. i want to use an if statement to stop the program from continuing if the input entered by the user is not correct (stored) in the txt files. else if the info is correct(stored in the txt files) than continue with the second part of the code which is the book inventory part. Please help me, this project is due today and im lost. idk what else to do. all i want do is to finish this project and at least to get a b on this assignment.

Demo:

if (condition == true) {

  // do something

} else {

  //do something else

}
if (input is invalid) {

  display an error notification
  react to error as appropriate for situation

} else {

  //input is assumed valid
  execute action 1
  execute action 2
  //etc...

}

Notice the braces around the sections controlled by the parts of the if - else statement...

You don't have your braces correct. You need to fix them.

There may be other problems, but that's the main one that I see.

Thank you Fbody and averybody else. ive fixed all the bugs i had and also included new details and thanks to u guys ive got an A in my presentation. thank you so much :-)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.