Code Skips?

#include <iostream>
#include <conio.h>
#include <string>
// Includes filestream
#include <fstream>

using namespace std;

// Objects can vary from class
class editText
{
// Public functions accessible outside class
public:
// Writing on a text file
void write()
{
string name[9];
string number[9];
char restart;
int count = 0;
int lastCount;

top:
cout <<"What is the person's name?" << endl << endl;
getline(cin, name[count]);
cin.clear();

cout << endl << "What is the person's phone number?" << endl << endl;
getline(cin, number[count]);
cin.clear();

lastCount = count;
cout << endl << "Is that all? y/n" << endl << endl;
cin >> restart;
cin.clear();

count++;

switch(restart)
{
case 'n':
cout << endl;
goto top;
break;
default:
cout << endl;
goto bottom;
break;
}

bottom:
ofstream iReadBook ("PhoneBook.txt", ios::app);

int x;

for(x = 0; x < (lastCount + 1); x++)
{
if(iReadBook.is_open())
{
iReadBook << name[x] << " " << number[x] << endl << endl;
}
}

iReadBook.close();

}

// Reading a text file
void read()
{
system("CLS");

string sReadBook;
ifstream iReadBook ("PhoneBook.txt");
if (iReadBook.is_open())
{
while (iReadBook.good())
{
getline(iReadBook,sReadBook);
cout << sReadBook << endl;
}
iReadBook.close();
}
}

// Clearing a text file
void clear()
{
ofstream iReadBook ("PhoneBook.txt", ios::trunc);
iReadBook.open("PhoneBook.txt");
iReadBook.close();
}

// Semicolon ends class
};

void main()
{
char view;
char clear;
editText edit;

edit.write();

cout << endl << "Would you like to view your phonebook? y/n" << endl << endl;
cin >> view;
cin.clear();

switch(view)
{
case 'y':
edit.read();
break;
default:
cout << endl;
break;
}

cout << "Would you like to clear your phonebook? y/n" << endl << endl;
cin >> clear;
cin.clear();

switch(clear)
{
case 'y':
edit.clear();
_getch();
break;
default:
cout << endl;
_getch();
break;
}
}
Last edited on
You need to use code tags, that is completely unreadable.

what he said, and also provide some explanation about what you want this code to do and what it does.
Topic archived. No new replies allowed.