Skipping input?

(Sorry for making another thread, Im doing a bit of catch up tonight)

Im working on this code, and it's not nearly done, but I like to check how certian things work as I go along. When I execute this, it outputs the menu, lets me select '1' and lets me input the employee name. After that, it skips all the other inputs, and I dont know why. The code's a bit of a hot mess now, but this one thing is bugging me. Here it is:

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
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

void GetData (string Namef[], int IdNumf[], float HoursWorkedf[], float HourlyRatef[], int &Indexf);
void ComputePay (float HoursWorkedf[], float HourlyRatef[], float GrossPayf[], int Indexf);
void PrintReport (string Namef[], int IdNumf[], float HoursWorkedf[], float HourlyRatef[], float GrossPayf[], int Indexf);
int menu();


const int MAXEMP = 10;

int main()
{
    char again;
    string Name[MAXEMP];
    int IdNum[MAXEMP], choice, Index;
    float HoursWorked[MAXEMP], HourlyRate[MAXEMP], GrossPay[MAXEMP];

do
{
    switch (menu())
    {
           case 1:
                cout<<"Enter Employee Data\n\n";
                GetData (Name, IdNum, HoursWorked, HourlyRate, Index);
                }  
           

    

}while ((again != 'N') && (again != 'n'));

return 1;

}

void GetData (string Namef[], int IdNumf[], float HoursWorkedf[], float HourlyRatef[], int &Index)
{
    int indexf = -1;
    string FirstName, LastName;
	char again;
    string Name;
    int IdNum;

do
{
indexf++;
again = 'y';
	cout<<"Employee number "<<indexf + 1<<":\n";
    cout<<"Please enter your first and last name seperated by a space:\t";
	cin>>Namef[indexf];
	cout<<"\nPlease enter your four digit ID number:\t";
    cin>>IdNumf[indexf];
	cout<<"\nPlease enter the ammount of hours worked:\t";
	cin>>HoursWorkedf[indexf];
	cout<<"\nPlease enter the hourly rate:\t";
	cin>>HourlyRatef[indexf];
	Index = indexf;
    cout<<"Again?";
    cin>>again;
    } while ((again != 'n') && (again != 'N'));
    return;
}


int menu()
{
	int choice;
	int ok = 1;
	cout<<"\n\n\n";
    cout<<"\t\tWelcome to the CSC 110 Payroll Program"<<endl;
    cout<<"\t\t\tPlease choose from the following:"<<endl;
    cout<<"\n\n\n";
    cout<<"1. Enter Employee Data"<<endl;
    cout<<"2. Compute Gross Pay"<<endl;
    cout<<"3. Edit Employee Data"<<endl;
    cout<<"4. Sort Employee Records"<<endl;
    cout<<"5. Print Report"<<endl;
    cout<<"6. Exit"<<endl;
    cin>>choice;

    do
	{
		if ((choice < 1) || (choice > 6))
		{
			cout<<"Invalid choice. Please try again.\n";
			ok = 0;
			system ("PAUSE");
			system ("CLS");
		}
	} 
	while (!ok);

	return choice;
}


Any help would be great, I'm really stuck here. Thank you.
Last edited on
Hate to bump, but I really need something to go on, even if it's just a general direction.
Have you tried to use a line such as cin.clear(); or cin.ignore(80,'\n'); after the cin prompts?
Also I notice you don't have a break statement at the end of the first case in your switch block. I know you don't have more cases yet, but don't forget the break statements at the end of cases when you add more. I've done that plenty of times.
Last edited on
have you tried cin.sync () before cin >> ?
Topic archived. No new replies allowed.