C++ Function problem

So for my assignment i need to input a name and then call a function to see if the name is valid then give them a code. I'm not sure what to put in the
 
 ChangeName(name2);

on the 10th line
and also is there any to cut down on the if statements

Here is the full 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <string>
using namespace std;
string ChangeName (string name);
int main ()
{//start
	string name2;
cout << "Please enter your name" << endl;
cin >> name2;
ChangeName(name2);//Calls the ChangeName function
system ("PAUSE");
return 0;

}

string ChangeName (string name2)
{//start 
	if (name2 == "Carl")
	{
	cout <<"C531006"<< endl;
	}
	else 
		if (name2 == "Elle")
		{
		cout <<"C531007" << endl; 
		}
		else
			if (name2 == "Keith")
			{
			cout <<"C531010" <<endl;
			}
			else
				if (name2 == "Prad")
				{
				cout <<"C532011"<<endl;
				}
				else
					if (name2 == "Molly")
					{
					cout << "C532015" << endl;
					}
					else
						if(name2 == "Bunmi")
						{
						cout << "C531178" <<endl;
						}
						else
							if(name2 == "Kim")
							{
								cout<< "C532196" << endl;
							}
							else
								cout << name2 << "You are not required dto take the test" << endl;
	return 0;
}//end

Last edited on
Your changeName function could just be void. You don't really need this function to return anything.

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>

using namespace std;

void changeName(string);

int main(){
	string name;
	
	cout << "Please enter your name" << endl;
	cin >> name;
	changeName(name);
	
	return 0;

}//main

void changeName(string name){
	if (name == "Carl")
		cout << "C531006" << endl;
	else if (name == "Elle")
		cout << "C531007" << endl;
	else if (name == "Keith")
		cout << "C531010" << endl;
	else if (name == "Prad")
		cout << "C532011" << endl;
	else if (name == "Molly")
		cout << "C532015" << endl;
	else if (name == "Bunmi")
		cout << "C531178" << endl;
	else if (name == "Kim")
		cout << "C532196" << endl;
	else
		cout << name << "You are not required to take the test" << endl;
}//changeName 

Oh cool thank you so much :D
Topic archived. No new replies allowed.