Hello, I have a strange problem and I need some help... I am working with a project that the compiler create a txt file and save the informations of the user as the user enter... The program create only ONE file and overwrite eatch time... The problem is that the compiler create a new TXT file and isn't save the details into the data.txt but on that txt file that is invalid encoding... Any ideas about that?? Also the program must have a rent movie option and a return movie, if the user rent a movie the program will just subtract -1$ from the account and rent the movie, and print the current balance and if user now want to return a movie the program will just print out that the user return a number of movies end print again out the current balance of the user.... ( I thing this is ok I don't really need help with the return movie selection..) And at the end the program will search by the option phone_number or last_name and print out all the information of the user.... Below is my half code since I have just started the program... Please if you any ideas let me know as soon as possible since is final project year and I need to hand over TODAY!!! At the end I don't WANT to finished my project I want only a POINT!!!

Thank you very much!!!
Regards

//============================================================================
// Name        : COMP113_Project.cpp
// Author      : 
// Version     : 1.0V
// Copyright   : 2012@ copyright
// Description : Video Store Managment Project in C++
// Student ID  : //============================================================================

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

using namespace std;

char value;

int close(int argc, char *arvg[]);
int open_acount(int argc, char *argv[]);
int main_menu(int argc, char *argv[]);
int quit();
int main();




int quit()
{
	char option2;

	cout <<"Are you sure you want to quit from the program? (Y/N): "<<endl;
    cin >> option2;    // the program ask from user if he/she wants to quit or not

	if ((option2=='Y') || (option2=='y'))   // if statement that check the  input of the user
	{ //start brackets of if statement
		cout <<"GoodBye!!! C ya later!!!.. "<<endl;  // goodbye message if the user wants to quit end the program exit at next line
		cout <<"Do you want to save your work now?? (Y/N): "<<endl;

		return(1);
	}//end brackets of if statement
	else // else of if statement
		if ((option2=='N') || (option2=='n'))  //if statement check if the user select N/n and continues
		{ //start bracket of if statement
			cout <<"You will now return to main menu!"<<endl;  //print message that the program will return to main menu
		    main();
		}// end bracket of if statement
		else  //else of the second if statement
			cout << "Error input..."<<endl; // print an error message and inform the user that the program
			cout << endl;
	return(0);
}

int close()
{
	int i,number;
	char name1[50];
	string data[200];

	i =-1;
	ifstream out(name1);
	do
	{
		i++;
		out>>data[i];

	}
	while (data[i]!="");
		cout <<"Please enter an account number: ";
	    cin >>number;
	    for (int j=(number-1)*6; j<=(number-1)*6+5; j++)
	    {
	    	data[j]="";
	    }
	    ofstream in(name1);
	    for (int j=0; j<=i; j++)
	    	in<<data[j]<<endl;
	    in.close();
	    cout <<"Account has been close.!!"<<endl;
	    main();
	    return 0;
}



int open_acount()
{
	int i, phone,post,number;
	string name, last_n,address,city,data[200];
    char name1[50];

	i = -1;
	ifstream out(name1);
	do
	{	i++;
	    out>>data[i];
	}
	while (data[i]!="");
	out.close();
	number=(i+1)/6;
	cout <<"Enter first name: ";
	cin >>name;
	cout <<"Enter last name: ";
	cin >>last_n;
	cout <<"Enter phone number: ";
	cin >> phone;
	cout <<"Enter street address: ";
	cin >>address;
	cout <<"Enter City: ";
	cin >> city;
	cout <<"Enter Post Code: ";
	cin >>post;
	cout <<"Number of account is: "<<number+1<<endl;
	ofstream in (name1);

	for (int j=0; j<=i; j++)
		in<<data[j]<<endl;
	in<<name<<endl;
	in<<last_n<<endl;
	in<<phone<<endl;
	in<<address<<endl;
	in<<city<<endl;
	in<<post<<endl;
	in<<number<<endl;
	in.close();
	main();
	return 0;

}
int main_menu()
{
	char name1[50];
	bool p;
	char operation;
	do
	    {
	    cout <<"Enter file name: "<<endl;
	    cin >>name1;
	    ifstream in(name1);
	    if (!in)
	    {
	        p=false;
	        cout<<"Error input"<<endl;
	    }
	    else p=true;
	    }
	    while (p==false);

	    cout <<"Account info is read in."<<endl;
	    cout <<endl;
	    cout <<"*********************"<<endl;
	    cout <<"o: open account"<<endl;
	    cout <<"c: close account"<<endl;
	    cout <<"d: deposit"<<endl;
	    cout <<"r: rent Movie"<<endl;
	    cout <<"t: return Movie"<<endl;
	    cout <<"a: account info"<<endl;
	    cout <<"p: print all accounts"<<endl;
	    cout <<"s: search for account"<<endl;
	    cout <<"q: quit"<<endl;
	    cout <<"*********************"<<endl;
	    cout <<"Enter operation: ";
	    cin >>operation;

	    switch (operation)
		{
	    case 'o':
	        open_acount();
	        break;

	    case 'c':
	    	close();
	        break;
	    return 0;
		}
}
int main()
{
	while (1)
	{

	cout <<"Do you want to read accounts from a file: (y/n)? ";
	cin >> value;

	if ((value == 'y') || (value == 'Y'))   // if statement of the option1
		{  // start bracket of if statement
		main_menu();   // called the calculator function if the option1 is 1

		} // end bracket of if statement
		else   // else of if statement

		if ((value == 'n') || (value == 'N'))  // if statement of option1 check if the user choose the second option
		{ //start bracket of if statement
	        if (quit() == 1)
	        {
	        	break; // break of the while loop to stop the while
	        }

		} // end of if statement

		else // else of if statement

			// if statement... check if the input of user is not 1 or 2
			// start bracket of if statement
			cout <<"Error Input. The program will now exit."<<endl; // prints out an error message if the user add a wrong input
            break;
	return main();

	}
}

anybody that can help??

Hello, I have a strange problem and I need some help... I am working with a project that the compiler create a txt file and save the informations of the user as the user enter...

So far, so good.

The program create only ONE file and overwrite eatch time... The problem is that the compiler create a new TXT file and isn't save the details into the data.txt but on that txt file that is invalid encoding... Any ideas about that??

Explain your problem clearly... Where in the code is this happening?

Also the program must have a rent movie option and a return movie, if the user rent a movie the program will just subtract -1$ from the account and rent the movie, and print the current balance and if user now want to return a movie the program will just print out that the user return a number of movies end print again out the current balance of the user.... ( I thing this is ok I don't really need help with the return movie selection..)

So what do you need help with? What is it you can't do?

And at the end the program will search by the option phone_number or last_name and print out all the information of the user....

Again, what's wrong with the code? What does it do wrong? And where?

I am posting for you the Description of assignment:::

Your video store application will support the following features:

A) Open a new account, i.e. register a new user. The information stored is: first name,
last name, address, and phone number. The account is also assigned a unique
account number.

B) Close an account. All the information stored about the particular customer is
deleted. An account cannot be closed if the user has not returned all the movies.

C) Deposit a given amount to an account. The user has to provide the account
number.

D) Rent movies. The user has to provide the account number and at no time can the
balance of the account be less than zero or the user rent more than three movies at any given time. The cost of renting one movie is 1 Euro, which is deducted automatically when the user rents the movie.

E) Return a movie. The user has to provide the account number and the number of movies that the user is returning. A user cannot return more movies than she has rented

F) Display account information when given the account number. ü Print all the accounts sorted on customer account number, or the amount in the
account.

G) Search and display the accounts based on customer last name, or phone number.

H) Save all the accounts to a file and also allow to read in from a file


My problem is with open account, rent movie, return movie and with search function..
open account problem::::

The compiler create one TXT file each time that the user enter data.txt (different of data.txt) I want to create only one file;


Rent movie::: Here my problem is that I need function (pass by reff. probably) to return the balance from the depose() function and calculate the total balance after the user rent 2 movie... etc:: enter amount to depose: 10 then goes to rent movie:: enter number of movies 2-- The total balance is now 8 ( 10(current balance) - 2 (rent movies ) = 8;

at the search the user will select how to search account (last_name or phone_num) and will print out the all the informations of the Account number etc name, address..

below I have post an example of the output!!!

Do you want to read in accounts from a file (y/n)? y

Enter file name: testStore.tx Error cannot read in file!

Enter file name: testStore.txt Account info is read in.

o: Open account 

c: Close account 

d: deposit 

r: Rent Movie

t: Return Movie 

a: Account info 

p: Print all accounts 

s: Search for account

q: quit Enter operation: o 

Enter first name: poolet

Enter last name: poolet2000

Enter phone number: 99 123455

Enter street adr: 1 infinite loop 

Enter City: Nicosia 

Enter Post code: 2130 

The account number is: 101 

o: Open account ..... 

q: quit

Enter operation: d 

Enter account number: 101 

Enter amount: 20 

20€ deposited to account 101 

o: Open account ..... 

q: quit Enter operation: r 

Enter account number: 101 

You have rented 1 movie(s) Current balance: 19€




o: Open account ..... 

q: quit Enter operation: 

r Enter account number: 101 

You have rented 2 movie(s) Current balance: 18€

o: Open account ..... 

q: quit 

Enter operation: a 

Enter account number: 101 

Account 101 belongs to poolet

1 infinite loop, 2130 Nicosia 

Phone: 99 123455 

Current balance: 18€ Current no. movie(s): 2

o: Open account ..... 

q: quit Enter operation: s 

Enter search option 

1: last name

2: phone number 

Enter search option: 2

Enter phone number: 99 123455

Account 101 belongs to poolet

1 infinite loop, 2130 Nicosia

Phone: 99 123455

Current balance: 18€ Current no. movie(s): 2

o: Open account ..... 

q: quit

Enter operation: q 

Do you want to save the information to a file (y/n)? y 

Enter file name: poolet.txt Account info is saved

Try outputting the value entered immediately after you input it to make sure what you typed in is actually in the value.

By the way, you have phone as an integer. Are you going to do math on it? If not why make it an integer?

Try outputting the value entered immediately after you input it to make sure what you typed in is actually in the value.

By the way, you have phone as an integer. Are you going to do math on it? If not why make it an integer?

Hello and thank you for reply!! Of course I did, isn't helps since the compiler isn't store the value depose.... About the phone_number I am a little bit hurry and that's the reason that my code has a lot of mistakes

int deposit()
{
    int number,i;
    string data[200], depose;
    char name1[50];
    int total;

    i =-1;

	cout <<"Enter an account number: ";
	cin >>number;

	i = -1;
		ifstream out(name1);
		do
		{	i++;
		    out>>data[i];
		}
		while (data[i]!="");
		out.close();
	cout <<"Enter amount that you want to depose:";
	cin >>depose;

    total = atoi(depose.c_str());
    if (depose == 0) {
cout <<"Error input. Please enter only numbers.<<endl;
main();
}
else
    total = atoi(depose.c_str());
    cout <<"You have deposited "<<depose<<" into "<<number<<" account";
    
    for (int j=0; j<=i; j++)
    ofstream out(name1);
    ofstream out (depose);
    cout <<endl;
    main();
    return depose;

}

Again, is number to be used in math? Are you going to add it to anything? Make it a string and see what happens...

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.