Using Multiple Getlines() Language: C++

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Paul
    New Member
    • Jan 2012
    • 3

    Using Multiple Getlines() Language: C++

    Why can't I use multiple getlines()

    C++ Code:


    #include <iostream>
    #include <fstream>
    #include <string>
    #include <cstdlib>

    using namespace std;

    int main()
    {
    int choice=0;
    while(choice<6)
    {
    cout << "1. Add Entry Name, age and address" << endl;
    cout << "2. Edit Information" << endl;
    cout << "3. Delete Information" << endl;
    cout << "4. View" << endl;
    cout << "5. Exit program" << endl;
    cout << "Please pick a choice" << endl;
    cin >> choice;
    if(choice==1)
    {
    cout << "You chose to add an entry" << endl;
    cout << "Please enter your full name:" << endl;
    string name;
    getline(cin,nam e);
    cout << "Please enter your age:" << endl;
    string age;
    getline(cin,age );
    cout << "Please enter your address:" << endl;
    string address;
    getline(cin, address);
    ofstream myfile;
    myfile.open("C: \\users\\APAdal ian15\\Desktop\ \User_Informati on.txt");
    cout <<"Creating new file... Please wait..." << endl;
    myfile << name << endl;
    myfile << age << endl;
    myfile << address << endl;
    myfile.close();
    }



    system("PAUSE") ;
    return 0;
    }
    }
  • Andrew Paul
    New Member
    • Jan 2012
    • 3

    #2
    Someone please reply!

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      You have a return 0 inside your while loop. You hit it on the first pass and out you go.

      Comment

      • Andrew Paul
        New Member
        • Jan 2012
        • 3

        #4
        Originally posted by weaknessforcats
        You have a return 0 inside your while loop. You hit it on the first pass and out you go.
        Thanks man! Will try it out!

        Comment

        Working...