Ok so this is my code below in my member function definition .cpp file. The problem is when I execute the program it will not let me fill the answer for the first question so for example the output is:

Please enter the name of the receiver: Please enter the address of the receiver:
Please enter the city of the receiver:
Please enter the state of the receiver:
Please enter the zip code of the receiver:
and yada yada....
It completely skips the first one but will let me answer the rest of the questions and program continues to work as deisgned. Did I make a mistake somewhere where I used my strings or getline functions?

//Package class member-function definitions
#include <iostream>
using namespace std;

#include "package.h"

Package::Package(double weight, double cost)//constructor
{
	setWeight(weight);
	setCost(cost);
}

void Package::setSenderName()//set name
{
	cout << "Please enter the name of the sender: " << endl;
	getline(cin, sName);
}

string Package::getSenderName() const//return name
{
	return sName;
}

void Package::setSenderAddress()//set address
{
	cout << "Please enter the address of the sender: " << endl;
	getline(cin, sAddress);
}

string Package::getSenderAddress() const//return address
{
	return sAddress;
}

void Package::setSenderCity()//set city
{
	cout << "Please enter the city of the sender: " << endl;
	getline(cin, sCity);
}

string Package::getSenderCity() const//return city
{
	return sCity;
}

void Package::setSenderState()//set state
{
	cout << "Please enter the state of the sender: " << endl;
	getline(cin, sState);
}

string Package::getSenderState() const//return state
{
	return sState;
}

void Package::setSenderZipCode()//set zip code
{
	cout << "Please enter the zip code of the sender: " << endl;
	getline(cin, sCode);
}

string Package::getSenderZipCode() const//return zip code
{
	return sCode;
}
/***********************************************************************************************/
void Package::setReceiverName()//set name
{
	cout << "Please enter the name of the receiver: " << endl;
	getline(cin, rName);
}

string Package::getReceiverName() const//return name
{
	return rName;
}

void Package::setReceiverAddress()//set address
{
	cout << "Please enter the address of the receiver: " << endl;
	getline(cin, rAddress);
}

string Package::getReceiverAddress() const//return address
{
	return rAddress;
}

void Package::setReceiverCity()//set city
{
	cout << "Please enter the city of the receiver: " << endl;
	getline(cin, rCity);
}

string Package::getReceiverCity() const//return city
{
	return rCity;
}

void Package::setReceiverState()//set state
{
	cout << "Please enter the state of the receiver: " << endl;
	getline(cin, rState);
}

string Package::getReceiverState() const//return state
{
	return rState;
}

void Package::setReceiverZipCode()//set zip code
{
	cout << "Please enter the zip code of the receiver: " << endl;
	getline(cin, rCode);
}

string Package::getReceiverZipCode() const//return zip code
{
	return rCode;
}
/**********************************************************************************************/
void Package::setWeight(double pweight)//set weight
{
	if(pweight < 0.0)
	{
		weight = 0.0;

	} else
	{
		weight = pweight;
	}
}

double Package::getWeight() const//return weight
{
	return weight;
}

void Package::setCost(double pcost)//set cost
{
	if(pcost < 0.0)
	{
		cost = 0.0;

	} else
	{
		cost = pcost;
	}
}

double Package::getCost() const//return cost
{
	return cost;
}

double Package::calculateCost() const//calculates cost of sending a package
{
	return weight * cost;
}

void Package::setInfo()
{
	setSenderName();
	setSenderAddress();
	setSenderCity();
	setSenderState();
	setSenderZipCode();
	/*******/
	setReceiverName();
	setReceiverAddress();
	setReceiverCity();
	setReceiverState();
	setReceiverZipCode();
}

void Package::print()//sender and receiver information
{
	setInfo();
	
	cout << "Sender's Information: \n";	
	cout << sName << ' ' << "\n" << sAddress 
		 << "\n" << sCity << ", " << sState << ' ' << sCode << endl;

	cout << "\nReceiver's Information: \n";
	cout << rName << ' ' << "\n" << rAddress 
		 << "\n" << rCity << ", " << rState << ' ' << rCode << endl;

@Corby, Assuming the followig Package.h, it worked fine for me.. started taking input from sender's name to receiver's zip code, and then outputted data in proper format too, though i had to add main function to the cpp file because yours is not visible in the code you submitted.. Let's know what the exact problem is..

/***** Package.h *********/

#include <string>

class Package
{

private:
	string sName;
	string sAddress;
	string sCity;
	string sState;
	string sCode;
	string rName;
	string rAddress;
	string rCity;
	string rState;
	string rCode;
	double weight;
	double cost;

public:
	Package(double weight = 0.0, double cost = 0.0);

	//getter-setter functions
	void setSenderName();
	string getSenderName() const;
	void setSenderAddress();
	string getSenderAddress() const;
	void setSenderCity();
	string getSenderCity() const;
	void setSenderState();
	string getSenderState() const;
	void setSenderZipCode();
	string getSenderZipCode() const;
	string getReceiverName() const;//return name
	void setReceiverName();//set name
	void setReceiverAddress();//set address
	string getReceiverAddress() const;//return address
	void setReceiverCity();//set city
	string getReceiverCity() const;//return city
	void setReceiverState();//set state
	string getReceiverState() const;//return state
	void setReceiverZipCode();//set zip code
	string getReceiverZipCode() const;//return zip code
	void setWeight(double pweight);//set weight
	double getWeight() const;//return weight
	void setCost(double pcost);//set cost
	double getCost() const;//return cost
	double calculateCost() const;//calculates cost of sending a package
	void setInfo();
	void print();//sender and receiver information

};

Can you post package.h if it's not too big?

heres the .h file

//Package Class definition
#ifndef PACKAGE_H
#define PACKAGE_H

#include <string>
using namespace std;

class Package
{
public:
	Package(double = 0.0, double = 0.0);//constrcutor
	void setSenderName();
	string getSenderName() const;
	void setSenderAddress();
	string getSenderAddress() const;
	void setSenderCity();
	string getSenderCity() const;
	void setSenderState();
	string getSenderState() const;
	void setSenderZipCode();
	string getSenderZipCode() const;
	/*******/
	void setReceiverName();
	string getReceiverName() const;
	void setReceiverAddress();
	string getReceiverAddress() const;
	void setReceiverCity();
	string getReceiverCity() const;
	void setReceiverState();
	string getReceiverState() const;
	void setReceiverZipCode();
	string getReceiverZipCode() const;
	/**********/
	void setWeight(double);
	double getWeight() const;
	void setCost(double);
	double getCost() const;
	double calculateCost() const;
	void setInfo();
	void print();
protected:
	string sName;
	string sAddress;
	string sCity;
	string sState;
	string sCode;
	string rName;
	string rAddress;
	string rCity;
	string rState;
	string rCode;
	double weight;
	double cost;
};

#endif

@Corby, Assuming the followig Package.h, it worked fine for me.. started taking input from sender's name to receiver's zip code, and then outputted data in proper format too, though i had to add main function to the cpp file because yours is not visible in the code you submitted.. Let's know what the exact problem is..

/***** Package.h *********/

#include <string>

class Package
{

private:
	string sName;
	string sAddress;
	string sCity;
	string sState;
	string sCode;
	string rName;
	string rAddress;
	string rCity;
	string rState;
	string rCode;
	double weight;
	double cost;

public:
	Package(double weight = 0.0, double cost = 0.0);

	//getter-setter functions
	void setSenderName();
	string getSenderName() const;
	void setSenderAddress();
	string getSenderAddress() const;
	void setSenderCity();
	string getSenderCity() const;
	void setSenderState();
	string getSenderState() const;
	void setSenderZipCode();
	string getSenderZipCode() const;
	string getReceiverName() const;//return name
	void setReceiverName();//set name
	void setReceiverAddress();//set address
	string getReceiverAddress() const;//return address
	void setReceiverCity();//set city
	string getReceiverCity() const;//return city
	void setReceiverState();//set state
	string getReceiverState() const;//return state
	void setReceiverZipCode();//set zip code
	string getReceiverZipCode() const;//return zip code
	void setWeight(double pweight);//set weight
	double getWeight() const;//return weight
	void setCost(double pcost);//set cost
	double getCost() const;//return cost
	double calculateCost() const;//calculates cost of sending a package
	void setInfo();
	void print();//sender and receiver information

};

for me when i execute the program it will do this first:
Please enter the name of the sender:
Please enter the address of the sender:
It does not allow me to enter info for the person's name; it skips right to the address part

Seg fault maybe? I would try using a different compiler, and if you still have issue, send the rest of the cpp file, and i'll try compiling it on my machine. I would be interested in seeing how you instantiate the class, for example.

Does it accept all the inputs from 2nd string onwards properly? Also, does it output them all properly later? Also, what does it output as sender's name?
What I am hinting is that, if the problem is only with the first input, there may be a problem with getline function in whichever compiler or platform you're using..

Seg fault maybe? I would try using a different compiler, and if you still have issue, send the rest of the cpp file, and i'll try compiling it on my machine. I would be interested in seeing how you instantiate the class, for example.

hey thx for your help but it was the compiler's fault. all i need to add in before my first string was cin.ignore(1);

Edited 6 Years Ago by corby: n/a

Does it accept all the inputs from 2nd string onwards properly? Also, does it output them all properly later? Also, what does it output as sender's name?
What I am hinting is that, if the problem is only with the first input, there may be a problem with getline function in whichever compiler or platform you're using..

yea it was a problem with the compiler...i add cin.ignore(1) before the first string

What I am hinting is that, if the problem is only with the first input, there may be a problem with getline function in whichever compiler or platform you're using..

hey thx for your help but it was the compiler's fault. all i need to add in before my first string was cin.ignore(1);

Interesting that lack of knowledge of C++ input means the problem is the fault of the compiler. Sorry guys, it's not the compiler. There are gaps in your understanding. But don't worry about that. You'll fill in those gaps as you go. It is complicated.

Interesting that lack of knowledge of C++ input means the problem is the fault of the compiler. Sorry guys, it's not the compiler. There are gaps in your understanding. But don't worry about that. You'll fill in those gaps as you go. It is complicated.

dude u need to chill out cause clearly it is the compiler problem...when i used another, my program worked fine. i added the cin.ignore(1) cause i have to use my schools compiler and it just so happens to act in such a way...dont comment unless you have anything intelligent to add

Yess suh, masta. I'z chilled.

You obviously know better than the rest of us. Sorry.

never said that. just dont say anything unless it is constructive or helpful thats all

So mentioning that it's not the compiler's fault when it is clearly the programmer's lack of knowledge is not constructive? Sorry. My mistake.

So mentioning that it's not the compiler's fault when it is clearly the programmer's lack of knowledge is not constructive? Sorry. My mistake.

how can it be a lack of knowledge when i clearly fixed the probelm? and all compilers are different, so some stuff works on some and not others, hence the compiler executes the program differently hence the compiler can be a problem....once again if u have nothing constructive to add just leave and be gone

This question has already been answered. Start a new discussion instead.