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();
}
}