Writing a first and last name readable over 2 file matching programs
<p>I'm writing a file matching program for a project for school.  The idea is that one program allows you to enter info as follows: 1000 (acct number)  Jane Doe  54.50 (balance). Then allow you to enter the account number and a transaction amount for the second program to combine and update a new master file. </p>

<p>The programs are working together just fine (the second one takes information from the first, including any transactions and updates the new balance - searching by account number) but the problem I am running into is with the name. </p>

<p>---Wasn't clear here.  When I ask for a name and I put in a single string of characters, the program works fine, if I try to put in a full name, like Jane Doe I go into the loop mentioned below.</p>

<p>I've tried char name[20] which puts me into an infinite loop and I have to 'x' out of the program and I've tried assigning first and lastName to string.  That worked for the writing but the program that takes the input file oldMaster and the transaction file inTransaction then outputs a new file newMaster, doesn't recognize the name.</p>

<p>I've tried getline also which isn't working for me, probably programmer error.  </p>

<p>Should this be done as an array, if that's possible for this?  I think I'm getting hung up on the fact that I am editing files.  Answers are fine - but I like to figure it out on my own, just looking for a little guidance on where to go from here.</p>

<p>Hopefully this was fairly clear - if not I'll be happy to explain again in a different way.  Just frustrated that I'm this close and can't solve it.</p>

<p>Thanks in advance!</p>

<pre><code>#include "stdafx.h"
#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;cstdlib&gt;
#include &lt;iomanip&gt;
using namespace std;



void createOldMaster()
{

    ofstream oldMaster;
    int accountNum;
    double balance;
    char name[15];

    oldMaster.open("oldmast.dat", ios::out);

    if(!oldMaster)
    {
        cout &lt;&lt; "Unable to open the file." &lt;&lt; endl;
        exit(1);
    } // end if

    cout &lt;&lt; "Enter the account number (0 to exit)." &lt;&lt; endl;

    while(true)
    {
        cout &lt;&lt; "Account Number: ";
        cin &gt;&gt; accountNum;  

        if(accountNum == 0)
            break;

        else
        {
                        \\ This is where it hangs up if I use a first and last name
            cout &lt;&lt; "\nName: "; 
            cin &gt;&gt; name;
            cout &lt;&lt; "\nBalance : " &lt;&lt; endl;
            cin &gt;&gt; balance;

            oldMaster &lt;&lt; accountNum &lt;&lt; " " &lt;&lt; name &lt;&lt; " " &lt;&lt; balance &lt;&lt; endl;

        }
    }

} //end createOldMaster

void createTransaction()
{

    ofstream inTransaction;
    int accountNum;
    double balance;

    inTransaction.open("trans.dat");

    if(!inTransaction)
    {
        cout &lt;&lt; "Unable to open the transaction file." &lt;&lt; endl;
        exit(1);
    }

    cout &lt;&lt; "Enter the account number and balance (0 to exit): " &lt;&lt; endl;

    while(true)
    {
        cout &lt;&lt; "Account Number: " &lt;&lt; endl;
        cin &gt;&gt; accountNum;

        if(accountNum == 0)
            break;

        else
        {
        cout &lt;&lt; "Balance: " &lt;&lt; endl;
        cin &gt;&gt; balance;

        inTransaction &lt;&lt; accountNum &lt;&lt; " " &lt;&lt; balance &lt;&lt; endl;

        }
    }
} //end createTransaction

int main()
{
    createOldMaster();
    createTransaction();

    return 0;
}
</code></pre>
