Thread: Error with function that attempts to fill an array

  1. #1
    Registered User
    Join Date
    Oct 2011
    Location
    Los Gatos, California, United States
    Posts
    19

    Error with function that attempts to fill an array

    I can't seem to get the syntax for this function right, I am getting an error related to the function setNewContact. This file includes the function definitions for one of the classes in my program. Any idea where this error comes from?

    Code:
    #include "Person.h"
    #include <iostream>
    using namespace std;
    
    
    /*This file contains the function definitions for class Person*/
    
    
    Person::Person()
    {
        nextEmptySpot=0;
    }
    
    
    //This function prompts the user to input the contact’s first name, last name, address, zip code, phone number, email, and notes
    //The user input gets placed in the contactList array
    void Person::enterNewContact()
    {
        cout << "\n\tCreate a new contact selected.\n" << endl << "\tPress <Enter> after each input. " << endl
        << "\nPlease input the First Name: ";
            getline(cin,firstName);
    
    
        cout << "Please enter the Last Name: ";
            getline(cin,lastName);
        if (lastName=="")
        {
            cout<<"Last Name is a required field. Please try again.";
        }
        else {
    
    
        cout << "\nPlease enter the Street Address, City,\nState, and  Country separated by commas: ";
            getline(cin,address);
    
    
        cout << "\nPlease input the ZIP code: ";
            getline(cin,zip);
    
    
        cout << "Please input the Telephone Number: ";
            getline(cin,phone);
    
    
        cout << "Please input the email address: ";
            getline(cin,email);
    
    
        cout << "Please input any other information: ";
            getline(cin,notes);
    }
    }
    //puts the new person object into the array
    void Person::setNewContact()
    {
        contactList[nextEmptySpot++]={firstName; lastName; address; phone; email; notes;}
    // function returns two errors 
        
    }
    These are the two compiler errors. I likely have the syntax for this function wrong.
    Code:
    error C2059: syntax error : '{'
    error C2143: syntax error : missing ';' before '{'
    I am trying to store the information inputted by the user in the function enterNewContact into one element of the array contactList.

    I appreciate your help.

  2. #2
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    You should get a better compiler that has better error messages, including line numbers.

    Edit:
    But whatever you're trying to do on line 56, it's not correct.
    Last edited by King Mir; 12-02-2011 at 09:54 PM.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  3. #3
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    Code:
    contactList[nextEmptySpot++]={firstName; lastName; address; phone; email; notes;}
    I see what you're going for, the correct syntax is
    Code:
    {arg1, arg2, ...}
    But this only works when initializing structs or arrays, you can't assign to variables like this
    Either 1)set each variable individually or 2)provide a set(firstName, lastName...) method

    @King Mir: looks like MSVC to me, it gives line numbers, OP just didn't copy them
    Last edited by bernt; 12-02-2011 at 09:56 PM.
    Consider this post signed

  4. #4
    Registered User
    Join Date
    Oct 2011
    Location
    Los Gatos, California, United States
    Posts
    19
    1>c:\users\username\documents\visual studio 2008\projects\quicksoft contact database\quicksoft contact database\person.cpp(56) : error C2059: syntax error : '{'
    1>c:\users\username\documents\visual studio 2008\projects\quicksoft contact database\quicksoft contact database\person.cpp(56) : error C2143: syntax error : missing ';' before '{'

    Here are the full error lines from visual studio 2008.

    The errors occur on line 56, inside the setNewContact Function.

    Thanks for your time.

  5. #5
    Registered User
    Join Date
    Oct 2011
    Location
    Los Gatos, California, United States
    Posts
    19
    Got everything figured out, Thanks for your help.
    Last edited by RRTT; 12-02-2011 at 10:48 PM. Reason: changed post

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fill the array help
    By IMMORTALX in forum C Programming
    Replies: 7
    Last Post: 09-09-2011, 03:34 AM
  2. Reporting SSH break-in attempts
    By _Mike in forum Tech Board
    Replies: 7
    Last Post: 03-25-2010, 01:22 PM
  3. Replies: 2
    Last Post: 04-27-2008, 03:39 AM
  4. Question regarding the fill function.
    By ChristianTool in forum C++ Programming
    Replies: 2
    Last Post: 03-13-2005, 09:08 PM
  5. Trying to fill an int array
    By boojus in forum C++ Programming
    Replies: 3
    Last Post: 11-21-2003, 02:31 PM