I'm making a student management system. All is working well, except the Delete Student Info function. I'm totally new in studying the C++ language.
When I try to use the Delete function, it will result like this, like a loop:
And this is my delete code:
void student::deleted()
{
system("cls");
fstream file, file1;
int found = 0;
string snum;
cout<<"\t\t\t\t-------------------------------------------\t\t\t"<<endl;
cout<<"\t\t\t\t---------Delete Student Information--------\t\t\t"<<endl;
file.open("Records.txt", ios::in);
if (!file)
{
cout << "\n\t\t\tNo information is available.";
file.close();
}
else
{
cout <<"\nEnter Student Number you want to remove: ";
cin >> snum;
file1.open("Records1.txt", ios::app | ios::out);
file >> student_num >> name >> bday >> address >> gender >> degree >> year;
while (!file.eof())
{
if(snum != student_num)
{
file1 << " " << student_num << " " << name << " " << bday << " " << address << " " << gender << " " << degree << " " << year ;
} else
{
found==0;
cout <<"\n\t\t\tSuccessfully Deleted.";
}
}
file1 >> student_num >> name >> bday >>address >> gender >> degree >> year ;
if (found == 0)
{
cout <<"\n\t\t\tStudent Number not found.";
}
file1.close();
file.close();
remove("Records.txt");
rename("Records.txt", "NewRecords.txt");
}
All is working on my program, except this delete function. I hope you can enlighten me with knowledge I still not know.
Basically, your whole while loop is structured wrong. Try something more like this instead:
void student::deleted()
{
system("cls");
cout<<"\t\t\t\t-------------------------------------------\t\t\t"<<endl;
cout<<"\t\t\t\t---------Delete Student Information--------\t\t\t"<<endl;
ifstream inFile("Records.txt");
if (!inFile)
{
cout << "\n\t\t\tCan't open file.";
return;
}
ofstream outFile("NewRecords.txt");
if (!outFile)
{
cout << "\n\t\t\tCan't create new file.";
return;
}
cout << "\nEnter Student Number you want to remove: ";
string snum;
cin >> snum;
bool found = false;
while (inFile >> student_num >> name >> bday >> address >> gender >> degree >> year)
{
if (snum == student_num)
{
found = true;
}
else if (!(outFile << " " << student_num << " " << name << " " << bday << " " << address << " " << gender << " " << degree << " " << year)
{
cout << "\n\t\t\tCan't write to new file.";
outFile.close();
remove("NewRecords.txt");
return;
}
}
if (!inFile.eof())
{
cout << "\n\t\t\tCan't read information.";
outFile.close();
remove("NewRecords.txt");
return;
}
outFile.close();
inFile.close();
if (!found)
{
cout <<"\n\t\t\tStudent Number not found.";
remove("NewRecords.txt");
return;
}
if (rename("Records.txt", "OldRecords.txt") != 0)
{
cout <<"\n\t\t\tCan't backup old file.";
remove("NewRecords.txt");
return;
}
if (rename("NewRecords.txt", "Records.txt") != 0)
{
cout <<"\n\t\t\tCan't rename new file.";
rename("OldRecords.txt", "Records.txt");
return;
}
remove("OldRecords.txt");
cout <<"\n\t\t\tSuccessfully Deleted.";
}
Related
I'm trying to store multiple structs into an file and my problem is that when I try to add 2 structs into the same file, my second struct overwrites my first struct and when I go print out my first struct, its print out my second struct. I want to have multiple structs in my file that I can display one at a time and edit them one at a time if I want. Any clue on what's wrong with my code?
int main()
{
Record record1;
Record record2;
int choice;
int choice2;
cout << "Welcome to your Records! What do you want to do today?" << endl;
cout << endl << endl;
while(choice2 != -1)
{
cout << " " << endl;
cout << "1) Add new records to the file" << endl;
cout << "2) Display any record in the file" << endl;
cout << "3) Change any record in the file" << endl;
cout << "4) Exit" << endl;
cout << "Your Choice: ";
cin >> choice;
while(choice < 1 || choice > 4)
{
cout << "Invalid choice! Enter again" << endl;
cin >> choice;
}
if(choice == 1)
{
ofstream outFile("RecordFile.dat", ios::out | ios::binary);
AddItem(outFile);
outFile.close();
}
else if(choice == 2)
{
ifstream inFile("RecordFile.dat",ios::out | ios::binary);
DisplayItem(inFile);
inFile.close();
}
else if(choice == 3)
{
ofstream outFile("RecordFile.dat", ios::out | ios::binary);
EditItem(outFile);
outFile.close();
}
else if(choice == 4)
{
choice2 = -1;
}
}
return 0;
}
Header File
struct Record
{
char name[15];
int quantity;
double wholesalecost;
double retailcost;
};
void AddItem(ofstream& outFile);
void DisplayItem(ifstream& inFile);
void EditItem(ofstream& outFile);
Functions
void AddItem(ofstream& outFile)
{
Record record;
cout << "What is the name of this record: ";
cin.ignore();
cin.getline(record.name,15);
cout << "How many do we have(quantity): ";
cin >> record.quantity;
cout << "Whats the whole sale cost: ";
cin >> record.wholesalecost;
cout << "Whats the retail cost of " << record.name << ":";
cin >> record.retailcost;
if(outFile)
{
outFile.write((char*)&(record),sizeof(record));
}
else
{
cout << "File not Found" << endl;
}
}
void DisplayItem(ifstream& inFile)
{
Record record;
int recordnum;
cout << "Enter what record number you want to display " << endl;
cin >> recordnum;
recordnum--;
if(inFile)
{
inFile.seekg(sizeof(Record) * recordnum, ios::beg);
inFile.read(reinterpret_cast<char *>(&record), sizeof(record));
cout << "Name: " << record.name << endl;
cout << "Quantity: " << record.quantity << endl;
cout << "Whole Sale Cost: " << record.wholesalecost << endl;
cout << "Retail Cost: " << record.retailcost << endl;
}
else
{
cout << "File not found" << endl;
}
}
You are writing everything to the beginning of the file, so of course multiple writes overwrite eachother.
You need to define a file format that can contain multiple records and a way to find where to write new records that doesn't overlap with previous ones, as well as an easy way to find the location of existing records.
Have you considered just using a SQL (or other type of) database?
Unsure what I am doing wrong, I am only getting the value for the first while statement.
The value is calculated correctly, so I do not know what I did wrong.
Maybe someone can see something I cannot. I know you do not have the file it is reading from, but there should not be a need for this.
Any help is appreciated. I always seem to have issues with while loops.
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
string inputFileName;
string name, gender, college;
double score = 0, totalCC = 0, totalUN = 0, totalFemalesScore = 0, totalMalesScore = 0;
int ccCount = 0, unCount = 0, fCount = 0, mCount = 0;
ifstream inputFile;
cout << "Input file name: ";
getline(cin, inputFileName);
inputFile.open(inputFileName);
if (!inputFile.is_open())
{
cout << "Unable to open input file." << endl;
exit(1);
}
while (inputFile.peek() != EOF)
{
inputFile >> name >> gender >> college >> score;
cout << left << setw(17) << name << setw(4) << gender << setw(4) << college << setw(4) << score << endl;
}
cout << "\nEnd of file reached\n" << endl;
inputFile.clear();
inputFile.seekg(0);
while (inputFile >> name)
{
inputFile >> gender >> college >> score;
if (gender == "F")
{
totalFemalesScore += score;
fCount++;
}
}
while (inputFile >> name)
{
inputFile >> gender >> college >> score;
if (gender == "M")
{
totalMalesScore += score;
mCount++;
}
}
while (inputFile >> name)
{
inputFile >> gender >> college >> score;
if (college == "CC")
{
totalCC += score;
ccCount++;
}
}
while (inputFile >> name)
{
inputFile >> gender >> college >> score;
if (college == "UN")
{
totalUN += score;
unCount++;
}
}
cout << "\nEnd of file reached\n" << endl;
cout << fixed << showpoint << setprecision(2);
cout << "Average for females = " << totalFemalesScore / fCount << endl;
cout << "Average for males = " << totalMalesScore / mCount << endl;
cout << "Average of CC students = " << totalCC / ccCount << endl;
cout << "Average of UN students = " << totalUN / unCount << endl;
inputFile.close();
system("pause");
return 0;
}
Since you are accessing the values in these lines of code:
while (inputFile.peek() != EOF)
{
inputFile >> name >> gender >> college >> score;
cout << left << setw(17) << name << setw(4) << gender << setw(4) << college << setw(4) << score << endl;
}
Why not do the computation inside that loop:
while (inputFile.peek() != EOF)
{
inputFile >> name >> gender >> college >> score;
if (gender == "F")
{
totalFemalesScore += score;
fCount++;
} else {
totalMalesScore += score;
mCount++;
}
if (college == "CC")
{
totalCC += score;
ccCount++;
} else if (college == "UN") {
totalUN += score;
unCount++;
}
cout << left << setw(17) << name << setw(4) << gender << setw(4) << college << setw(4) << score << endl;
}
guys, i have a problem.
After i run the program, the console just crashes.
terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::replace: __pos (which is 4294967295) > this->size() (which is 9)
I mean, you will see.In the program there is an option "Add person", and when i add one, its all okay.But when i enter the program to add second person it crashes.Please, help!
The source code of the programs is:
#include <iostream>
#include <windows.h>
#include <string>
#include <algorithm>
#include <fstream>
using namespace std;
int main(){
system("chcp 1251 > nul");
system("title PeopleData");
string firstName;
string midName;
string lastName;
string fullName;
string line;
long ID = 27560000;
int age;
char gender;
cout << "1.Add person" << endl;
cout << "2.Read file" << endl;
cout << "3.Exit" << endl << endl;
cout << "Please, enter your choice: ";
int choice;
cin >> choice;
if(choice == 1)
{
system("cls");
ofstream myfile("Data.txt", ios::app);
ifstream file("Data.txt");
string IDLine;
int numberOfLines = 0;
if (myfile.is_open())
{
while (getline (file, line) )
{
numberOfLines ++;
}
file.close();
ifstream file("Data.txt");
int y = 0;
line = "";
while(getline(file, line))
{
IDLine = line;
if(y == numberOfLines - 5)
{
goto NextStep;
}
y++;
}
}
else
{
cout << "Unable to open file";
}
NextStep:
string LastID = IDLine;
if(LastID != "")
{
LastID.replace(LastID.find("ID: "), string("ID: ").length(), "");
ID = atoi(LastID.c_str()) + 1;
}
else
{
ID = 27560000;
}
cout << "First Name: ";
cin >> firstName;
cout << endl << endl;
cout << "Middle Name: ";
cin >> midName;
cout << endl << endl;
cout << "Last Name: ";
cin >> lastName;
cout << endl << endl;
cout << "Age: ";
cin >> age;
cout << endl << endl;
cout << "Gender (m / f): ";
cin >> gender;
fullName = firstName + " " + midName + " " + lastName;
myfile << "First Name: " << firstName << "\n";
myfile << "Middle Name: " << midName << "\n";
myfile << "Last Name: " << lastName << "\n";
myfile << "Full Name: " << fullName << "\n";
myfile << "Age: " << age << "\n";
myfile << "Gender: " << gender << "\n";
myfile << "ID: " << ID << "\n";
myfile << "\n---------------\n\n";
myfile.close();
file.close();
return 0;
}
if(choice == 2)
{
system("cls");
ifstream myfile ("Data.txt");
if (myfile.is_open())
{
while ( getline (myfile,line) )
{
cout << line << '\n';
}
myfile.close();
}
else
{
setcolor(12);
cout << "Unable to open file";
}
}
if(choice == 3)
{
return 0;
}
system("pause > nul");
return 0;
}
`
hello guys i'm trying to delete a full line from a ".txt" file when the user enters the book id
my text file looks like this :
[BOOK INFO]%Book Id : 1%title : Object oriented programming%[PUBLISHER
INFO]%publisher name : misr publish house%puplisher address
:adfaf%[AUTHOR(s) INFO]%Authors Name : ahmed%Nationality :
egyptian%Authors Name : eter%Nationality : american%[MORE
INFO]%PublishedAt : 3/3/2006%status :6.
[BOOK INFO]%Book Id : 2%title : automate%[PUBLISHER INFO]%publisher
name : misr%puplisher address :nasr city%[AUTHOR(s) INFO]%Authors Name
: ahmed khaled%Nationality : egyptian%Authors Name : ohammed
adel%Nationality : egyptian%[MORE INFO]%PublishedAt : 3/8/2005%status
:15.
the line starts from [book info] to the (.)
i should be able to delete the whole line when the user enter the id
but i don't know how or what function to use
my code is :
/*password is admin*/
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include<stdlib.h>
#include<iomanip>
#include<conio.h>
#define F1 59
#define ESC 27
using namespace std;
void list_all_books_1();
void list_available_books_2();
void borrow_books_3();
void search_for_abook_4();
void add_new_book_5();
void delete_books_6();
fstream d_base;
char path[] = "library books.txt";
void output(){
//this function for displaying choices only
cout << setw(77) << "***********************************" << endl;
cout << setw(71) << "1. List all books in library" << endl;
cout << setw(77) << "2. List available books to borrow " << endl;
cout << setw(72) << "3. Borrow a Book from library" << endl;
cout << setw(63) << "4. Search For a Book" << endl;
cout << setw(59) << "5. Add New Books" << endl;
cout << setw(59) << "6. Delete a Book" << endl;
cout << setw(62) << "7. EXIT The Library" << endl;
cout << setw(77) << "***********************************" << endl;
}
//=====================================================================================================================================================
struct books{
//identfying books with all needed things
string id, status;
string title, p_name, p_address;
string date;
};
struct author{
string aut_name;
string aut_nationality;
};
//=====================================================================================================================================================
//function for choice 1 showing the books
void list_all_books_1(){
ifstream show;
char all;
show.open(path, ios::in | ios::app);
while (!show.eof()){
show >> std::noskipws;
show >> all;
if (all == '%')
cout << "\n";
else if (all == '.')
cout << "\n\n\n";
else
cout << all;
}
cout << endl;
show.close();
}
//=====================================================================================================================================================
void list_available_books_2(){
ifstream available_books;
char x;
available_books.open(path, ios::in | ios::app);
while (!available_books.eof()){
available_books >> std::noskipws;
available_books >> x;
if (x == '%')
cout << "\n";
else if (x == '.')
cout << "\n\n\n";
else
cout << x;
}
cout << endl;
available_books.close();
}
//=====================================================================================================================================================
void borrow_books_3(){
}
//=====================================================================================================================================================
void search_for_abook_4(){
string idx;
int offset, i = 0;
string line;
cout << "enter the ID of the book you're looking for";
cin >> idx;
d_base.open(path, ios::in | ios::app);
while (!d_base.eof()){
getline(d_base, line);
if (((offset = line.find(idx, 0))) != string::npos){
cout << "Book found" << endl;
i++;
d_base.close();
}
}
if (i == 0){
cout << "couldn't find book" << endl << endl;
}
}
//=====================================================================================================================================================
//for choice 5 to fill books
void add_new_book_5(){
int aut_number, booksnumber;
books newbook[1000];
author aut[100];
cout << "how many books you want to add ? ";
cin >> booksnumber;
cout << "what books you want to add :" << endl;
d_base.open(path, ios::out | ios::app);
for (int i = 0; i < booksnumber; i++){
cout << "id please : "; cin >> newbook[i].id;
cout << "title : "; cin.ignore(); getline(cin, newbook[i].title);
cout << "publisher name :"; getline(cin, newbook[i].p_name);
cout << "publisher address : "; getline(cin, newbook[i].p_address);
d_base << "[BOOK INFO]" << "%Book Id : " << newbook[i].id << "%title : " << newbook[i].title;
d_base << "%[PUBLISHER INFO]" << "%publisher name : " << newbook[i].p_name << "%puplisher address :" << newbook[i].p_address;
d_base << "%[AUTHOR(s) INFO]";
cout << "how many authors for the books";
cin >> aut_number;
for (int j = 0; j < aut_number; j++){
cout << "author" << j + 1 << " name : "; cin.ignore(); getline(cin, aut[j].aut_name);
cout << "Nationality : "; getline(cin, aut[j].aut_nationality);
d_base << "% Authors Name : " << aut[j].aut_name << "% Nationality : " << aut[j].aut_nationality;
}
cout << "Publish date :"; getline(cin, newbook[i].date);
cout << "How many copies of " << newbook[i].title << " "; cin >> newbook[i].status;
d_base << "%[MORE INFO]";
d_base << "%PublishedAt : " << newbook[i].date << "%status :" << newbook[i].status << "." << endl;
}
d_base.close();
cout <<setw(76)<< "Books Have Been Saved Sucessfully" << endl;
}
//=====================================================================================================================================================
void delete_books_6(){
//deleting a book
}
//=====================================================================================================================================================
int main(){
char choice;
cout << "\n\n" << setw(76) << "{ welcome to FCIS library }\n\n";
do{
output();
cout << "- what do you want to do ? ";
cin >> choice;
if (choice == '1'){
system("cls");
list_all_books_1();
}
//this one for list available books
else if (choice == '2'){
system("cls");
list_available_books_2();
}
//this one for borrow a book
else if (choice == '3'){
system("cls");
borrow_books_3();
}
else if (choice == '4'){
system("cls");
search_for_abook_4();
}
//this one is for adding new books to the list
else if (choice == '5'){
system("cls");
string pass;
do{
cout << "you must be an admin to add new books." << endl << "please enter passowrd (use small letters) : ";
cin >> pass;
if (pass == "b")
break;
else if (pass == "admin"){
system("cls");
cout << "ACCESS GAINED WELCOME " << endl;
add_new_book_5();
}
else{
cout << "Wrong password try again or press (b) to try another choice";
continue;
}
} while (pass != "admin");
}
//this one for deleteing a book
else if (choice == '6'){
system("cls");
//not completed yet
}
else if (choice == '7'){
system("cls");
cout << "\n\n\n"<<setw(76) << "Thanks for Using FCIS LIBRARY" << endl;
break;
}
else
cout << "\nwrong choice please choose again\n\n";
} while (_getch()!=27);
}
i tried to use get line and search for matching id the delete the line if there's match but couldn't accomplish it
i'm beginner at c++ by the way
Read the whole file into a memory buffer. Delete what you don't want. Overwrite the existing file with the contents of your memory buffer.
You've now deleted what you did not want from the file.
The purpose of the following code is to take user input of 6 movie titles and realease dates, write that data to a file using fstream, then read the data into 2 string characters (line1 and line2) in a loop, such that the first loop will assign line1 and line2 the first movie title and year, and the second loop will assign line1 and 2 the 2nd movie title and year, and so on, until eof.
// array of structures
#include <iostream>
#include <string>
#include <sstream>
#include <istream>
#include <stdio.h>
#include <cctype>
#include <fstream>
#include <cassert>
#include <assert.h>
using namespace std;
#define NUM_MOVIES 6
struct movies_iit
{
string title;
int year;
}
films[NUM_MOVIES];
// global variables
char title[20], y, n;
int year;
string search;
// function 1
void sort_on_title(movies_iit films[], int n)
{
// Local struct variable used to swap records
movies_iit temp;
for (int i = 0; i < n - 1; i++)
{
for (int i = 0; i < n - 1; i++)
{
/* If s[i].title is later in alphabet than
s[i+1].title, swap the two records */
if (films[i].title > films[i + 1].title)
{
temp = films[i];
films[i] = films[i + 1];
films[i + 1] = temp;
}
}
}
}
//end function 1
//function query1 prototype
void query1(movies_iit movie);
// function query2 prototype
void query2(movies_iit movie);
// function 2 prototype
void printmovie(movies_iit movie);
int main()
{
// login
// username: user
// password: word
string mystr, pass, name, line1, line2;
int n;
char response;
// output object
ofstream fout("data.dat");
// input object
ifstream fin("data.dat");
assert(fin.is_open());
cout << "enter your username " << endl;
cin >> name;
cout << "enter your password " << endl;
cin >> pass;
cout << "\n" << endl;
if (name == "user" && pass == "word")
cout << "Welcome, user." << endl;
else
{
cout << "###" << "unrecognized username/password combination" << "\t" << "please try again" << "###" << endl;
system("PAUSE");
return 0;
}
cin.ignore(std::numeric_limits < std::streamsize > ::max(), '\n');
cout << "\n" << endl;
for (n = 0; n < NUM_MOVIES; n++)
{
cout << "Enter title: ";
getline(cin, films[n].title);
cout << "Enter year: ";
getline(cin, mystr);
stringstream(mystr) >> films[n].year;
}
cout << "\n" << endl;
for (int i = 0; i < NUM_MOVIES; ++i)
{
fout << films[i].title << "\n";
fout << films[i].year << "\n";
}
// sort records, function 1 call
sort_on_title(films, NUM_MOVIES);
cout << "\nYou have entered these movies:\n";
for (n = 0; n < NUM_MOVIES; n++)
printmovie(films[n]); // function 2 call
cout << "Perform an alphabetical search? (y/n)" << endl;
cin >> response;
if (response == 'y')
{
cout << "Please enter title" << endl;
cin >> title;
if (fin)
{
getline(fin, line1); // read first 2 recs
getline(fin, line2);
while (fin) // keep reading till the eof
{
if (line1 == "title")
{
cout << " >> " << line1 << endl;
cout << line2 << endl;
}
else
{
cout << line1 << endl;
cout << line2 << endl;
}
}
}
fin.close(); //close input file
response == n;
}
else if (response == 'n')
cout << "\n" << endl;
else
cout << "invalid entry" << endl;
cout << "\n" << endl;
}
// function 2 definition
void printmovie(movies_iit movie)
{
cout << movie.title;
cout << " (" << movie.year << ")\n";
}
// function query1 defintion
void query1(movies_iit movie)
{
if (movie.title == "title")
{
cout << " >> " << movie.title;
cout << " (" << movie.year << ")\n";
}
else
{
cout << movie.title;
cout << " (" << movie.year << ")\n";
}
}
// function query2 definition
void query2(movies_iit movie)
{
if (movie.year >= year)
{
cout << movie.title;
cout << " (" << movie.year << ")\n";
}
}
In the loop where I read values from the file into my strings, in my output it does not display the data stored in the strings. Why is that, and how can I fix the issue?
I realized that the code I originally posted didn't work; here is a functional one.
You need to close the 'fout' filestream before you try to read from it using 'fin'.
fout.close(); // <== Close the output file to flush the buffered I/O
The data you are writing to the file is likely buffered (not written to the file immediately). Your data.dat file is empty when you try to read it during your search.
Close the file in which data is being stored.
You are matching for string "title" and not input which user has provided.
getline() should be inside while loop ( as you want to match all the lines and not just 1st 2 records)
int main (){
//login
//username: user
//password: word
string mystr, pass, name, line1, line2;
int n;
char response;
//output object
ofstream fout ("data.dat");
//input object
cout << "enter your username "<<endl;
cin >> name;
cout << "enter your password "<<endl;
cin >> pass;
cout << "\n" << endl;
if (name == "user" && pass == "word")
cout << "Welcome, user." << endl;
else
{cout << "###" << "unrecognized username/password combination" << "\t" << "please try again" << "###" << endl;
//system("PAUSE");
return 0;
}
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
cout << "\n" << endl;
for (n=0; n<NUM_MOVIES; n++)
{
cout << "Enter title: ";
getline (cin,films[n].title);
cout << "Enter year: ";
getline (cin,mystr);
stringstream(mystr) >> films[n].year;
}
cout << "\n" << endl;
//###################################################################################################################
//write to file
//###################################################################################################################
for (int i = 0; i < NUM_MOVIES; ++i)
{
fout << films[i].title << "\n";
fout << films[i].year << "\n";
}
fout.close();
//sort records, function 1 call
sort_on_title(films, NUM_MOVIES);
cout << "\nYou have entered these movies:\n";
for (n=0; n<NUM_MOVIES; n++)
printmovie (films[n]); //function 2 call
ifstream fin("data.dat");
assert(fin.is_open());
//###################################################################################################################
//query 1
//###################################################################################################################
cout << "Perform an alphabetical search? (y/n)" << endl;
cin >> response;
if (response == 'y')
{cout << "Please enter title" << endl;
cin >> title;
if (fin.good())
{
while(!fin.eof()) //keep reading till the eof
{
getline(fin,line1); // read first 2 recs
if(!fin.eof())
getline(fin,line2);
if (line1 == title)
{
cout << " >> " << line1 << endl;
cout << line2 << endl;
}
// else
// {
// cout << line1 << endl;
// cout << line2 << endl;
// }
}
}
fin.close(); //close input file
response == n;
}
else if (response == 'n')
cout << "\n" << endl;
else
cout << "invalid entry" << endl;
cout << "\n" << endl;
}