Code Is skipping over parts when inputting.

Write a program to complete the employeeType struct on page 604. Prompt the user to input a employee's
firstName, middleName, lastName, empID, address, city, state, zip, hiremonth, hireday, hireyear, phone, email,
deptID and yearlysalary. Calculate the employee’s yearly salary to determine monthly salary.

The program should output the employee data in the following:

Name: firstName middleName lastName
EmpID: empID
Address: address
city, state, zip
Date Hired: hiremonth/hireday/hireyear
Phone: phone
Email: email
DeptID: deptID
Monthly Salary: monthly
Yearly Salary: yearlysalary


I have used the structs within structs but for some reason when it gets to the address part it will let me put the first part but then jumbles the rest together without letting me input the rest.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;
struct nameType {
	string firstname;
	string middlename;
	string lastname;};
struct addressType {
	string address;
	string city;
	string state;
	string zip; };
struct dateType {
	int hiremonth;	
	int hireday;
	int hireyear; };
struct contactType{
	string phone;
	string email; };
struct employeeType {
	nameType name;
	string empID;
	addressType address;
	dateType hireDate;
	contactType contact;
	string deptID;
	double yearlysal;
	double monthlysal;
	 };

	int main (){
		nameType name;
		addressType address;
		dateType hiredate;
		contactType contact;
		employeeType employee;
	cout << "What is the employees first name?" <<endl;
	cin >> name.firstname;
	cout << "What is the employees middle name?" <<endl;
	cin >> name.middlename;
	cout << "What is the employees last name?" <<endl;
	cin >> name.lastname;
	cout << "What is the employees  employee ID number?" <<endl;
	cin >> employee.empID;
	cout << "What is the employees address?" <<endl;
	cin >> address.address;
	cout << "What is the employees city?" <<endl;
	cin >> address.city;
	cout << "What state does the employee live in?" <<endl;
	cin >> address.state;
	cout << "What is the employees zipcode?" <<endl;
	cin >> address.zip;
	cout << "What month was the employee hired?" <<endl;
	cin >> hiredate.hiremonth;
	cout << "What day was the employee hired?" <<endl;
	cin >> hiredate.hireday;
	cout << "What yearwas the employee hired?" <<endl;
	cin >> hiredate.hireyear;
	cout << "What is the employees phone number?" <<endl;
	cin >> contact.phone;
	cout << "What is the employees email address?" <<endl;
	cin >> contact.email;
	cout << "What is the employees department ID?" <<endl;
	cin >> employee.deptID;
	cout << "What is the employees yearly salary?" <<endl;
	cin >> employee.yearlysal;

	employee.monthlysal = employee.yearlysal / 12;

	cout <<" Employee Details: " <<endl;
	cout <<" Name: " << name.firstname << " " << name.middlename << " " << name.lastname <<endl;
	cout <<" Employee Id: "<< employee.empID << endl;
	cout <<" Address: "<<  address.address << " " << address.city << " " << address.state<< " " << address.zip <<endl;
	cout <<" Date Hired: " <<hiredate.hiremonth << " " << hiredate.hireday<< " " <<hiredate.hireyear <<endl;
	cout <<" Phone Number: " << contact.phone <<endl;
	cout <<" Email: "<< contact.email<< endl;
	cout <<" Department Id: " << employee.deptID <<endl;
	cout <<" Monthly Salary: " <<employee.monthlysal <<endl;
	cout <<" Yearly Salary: " <<employee.yearlysal <<endl;



	}
Last edited on
I suppose the address you type in also consists of whitespace characters (like space).
when you're using cin >> with string, it will eat all until it bumps to space - and the rest is left in
the buffer...
and another string will look in the buffer first, get the leftovers from there and skip the user's input
Last edited on
You are completely correct, I forgot all about it doing that. This is what happens when you go 2 days without sleep because of finals. -.-

Thank you!
no problem :)
Topic archived. No new replies allowed.