Need Help ASAP!

Okay, so I suck. I can do most of the basic stuff with math in basic C++, but cannot seem to be able ti figure this out. I just cant get my head around it and I am in serious danger of failing my final if I do not figure it out. Here is the problem I am asked to build:
Create a program that will store a list of employees and their emails and show the email address for a specific employee. Then ask the user for an employee to email and show the user the email address of that employee. The employee names should be stored in a separate array from the employee emails. Assume there are no more than 10 employees.
I have tried so many different things at this point my brain is just lost and confused. Ill owe you a beer if you can save my butt! Thanks in advance

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
#include <iostream>
#include <string>
using namespace std;

int main ()
{
    string a, b, c, d, e, f, g, h, i, j, e1,e2,e3,e4,e5,e6,e7,e8,e9,e10;
    
    if (a != "Stop") {
        cout << "Please enter name for employee 1 (or “Stop”): ";
    cin >> a;
    
    cout << "Please enter name for employee 2 (or “Stop”): ";
    cin >> b;
    if (b == "Stop") {
        cout << endl;
    
    cout << "Please enter name for employee 3 (or “Stop”): ";
    cin >> c;
    if (c == "Stop") {
        cout << endl;
    
    cout << "Please enter email for employee 1:";
    cin >> e1;
    if (e1 == "Stop") {
        cout << endl;
        cout << '\n';
    
    cout << "Please enter email for employee 2:";
    cin >> e2;
    if (e2 == "Stop") {
        cout << endl;
    
    cout << "Please enter email for employee 3:";
    cin >> e3;
    if (e3 == "Stop") {
        cout << endl;
    }
}
    }}}
    cout << "Which employee’s email would you like? ";
    cin >> e1;
    cout << "The email address of " << a << "is:" << e2;
}
}
The employee names should be stored in a separate array from the employee emails.


Why don't you follow the instructions and create arrays for the names and emails ?

1
2
string names[10];
string emails[10];


If you need a refresher for arrays have a look here:
http://www.cplusplus.com/doc/tutorial/arrays/

You also should learn about loops:
http://www.cplusplus.com/doc/tutorial/control/#loops
Hey man check this code

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
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>

using namespace std;

int main() {

	string emp[10];
	string emails[10];
	int size;
	cout << "Enter the employees name and ids you want to enter" << endl;
	cin >> size;
	if (size > 10) {
		cout << "Enter number less than 10";
		exit(0);
	}
	for (int i = 0; i < size; ++i) {
		cout << "Enter name of employee " << i + 1 << endl;
		cin >> emp[i];
		cout << "Enter employee id of " << i + 1 << endl;
		cin >> emails[i];
	}

	int number;

	cout << "Which employee’s email would you like? ";
	cin >> number;
	if (number <= size) {
		cout << "The email address of " << emp[number - 1] << " is:"
				<< emails[number - 1];
	} else {
		cout << "Employee is not found";
	}
}
Thank you so much, both of you! I truly appreciate it!
I am trying to toy with it and make to end the first array with "Stop", so it will prompt to ask for the emails. If not, no big deal. I think I got the point.
Current Code

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
#include <iostream>
#include <string>
#include <fstream>
#include <cstdlib>

using namespace std;

int main() {
    
    string emp[10];
    string emails[10];
    int size;
    cout << "How many Employees? " << '\n';
    cin >> size;
    if (size > 10) {
        cout << "Enter number less than 10" << '\n';
    
    }
    for (int i = 0; i < size; ++i) {
        cout << "Enter name of employee " << i + 1 << '\n';
        cin >> emp[i];
        cout << "Please enter email for employee  " << i + 1 << endl;
        cin >> emails[i];
    }
    
    int number;

    cout << "Which employee’s email would you like? ";
    cin >> number;
    if (number <= size) {
        cout << "The email address of " << emp[number - 1] << " is:"
        << emails[number - 1] << '\n';
    } else {
        cout << "That is not an employee!" << '\n' << "Please try again" << '\n';
        
}
}
Last edited on
Topic archived. No new replies allowed.