Hi guys! I have started writing a program for phonebook which will add, delete, search, display and sort the information of a person. information will include firstname, lastname & phonenumber.
now I was testing the first part of the program which adds a contact. but my loop is not doing the work which i wsa ecpecting it to do.please look at the below code and help me find out the probelm...i wanted to add store firsatname at locatio i=0, j=0; then last name at location i=0, j=1 and the phonenumber at i=0, j=2. but my inner loop for j is working again and agian instead of just working for 3 times.
I have one more ques. is it possible to store a name(collection of characters) at location i=0, j=0 etc.. or it can just store one character.
please help the code written is below:
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
const char OUTPUT_FILE[] = "out1.txt";
void introMsg();
void selectionMsg(int& choice);
void addBlackBook(char& firstName, char& lastName, char& phonenumber, ofstream& outFile);
void checkFileOpen(ofstream& aoutFile);
char outputBlackBook();
void deleteFromBlackBook();
char searchBlackBook();
int main(){
ifstream inFile;
ofstream outFile;
outFile.open(OUTPUT_FILE, ios::app);
char firstName;
char lastName;
char phonenumber;
int choice;
int i;
int j;
introMsg();
selectionMsg(choice);
if(choice == 1){
addBlackBook(firstName, lastName, phonenumber, outFile);
}else if(choice == 2){
deleteFromBlackBook();
} else if (choice == 3){
searchBlackBook(firstName, lastName);
} else if (choice == 4){
outFile.open("out1.txt");
outputBlackBook(out);
}
return 0;
}
void introMsg(){
cout << "Welcome to your black book\n";
cout << " This program keeps track of your contacts\n";
cout << " You may add, delete, search, and output contacts from this book\n";
}
void selectionMsg(int& choice){
cout << "Type 1 to ADD a contact\n";
cout << "Type 2 to DELETE a contact\n";
cout << "Type 3 to SEARCH for contact\n";
cout << "Type 4 to OUTPUT ALL contacts\n";
cout << "Type exit to terminate the program\n";
cin >> choice;
}
void addBlackBook(char& firstName, char& lastName, char& phonenumber, ofstream& outFile){
for(int i = 0; i <= 500; i ++){
for(int j = 0; j < 3; ){
cout << "Type the contacts first name:\n";
cin >> firstName;
j++;
cout <<"Type the contacts last name:\n";
cin >> lastName;
j++;
cout <<"Type the phonenumber\n";
cin >> phonenumber;
}
cout << firstName << lastName << phonenumber << endl;
outFile << firstName << lastName << phonenumber << endl;
}
}
void checkFileOpen(ofstream& aOutFile){
if(aOutFile.fail()) {
cout << "output filed opened failed\n";
exit(1);
}
}
/**
char searchBlackBook(char& fName, char& lName) {
cout << "SEARCH FOR A CONTACT\n";
cout << "Type the contacts first name\n:";
cin >> fName;
cout << "Type the contacts last name\n";
cin >> lName;
for(int i = 0; i <=500; i ++){
for(int j = 0; j < 2; j++ ){
if (fName == firstName && lName == lastName) {
cout << "fName" << "lName" << endl;
}
}
}
}
char outputBlackBook(ifstream& aIn) {
cout << "OUTPUT ALL CONTACTS\n";
aIn.get();
}
void sortContacts() {
}
void swapContacts() {
}
*/