I am doing a challenge that asks the user a name and telephone number and then stores it in a file. This is what I have so far:
I just need help finishing it up.Code:#include <iostream> #include <fstream> #include <cctype> using namespace std; int main() { fstream dataFile("phones.dat", ios::out); if (!dataFile) { cout << "Error opening the file."; return 0; } const int NAME_LENGTH = 81; const int PHONE_LENGTH = 26; char name[NAME_LENGTH], phone[PHONE_LENGTH]; cout << "This program allows you to add names and phone\n"; cout << "numbers to phones.dat.\n"; do { char add; cout << "Do you wish to add an entry? "; cin >> add; if (toupper(add) == 'Y') { cout << "Pleas enter a name and phone number: " << endl; cin.get(name, phone); dataFile.put(name, phone); } } while (toupper(add) == 'Y'); dataFile.close(); return 0; }



LinkBack URL
About LinkBacks


