Structure Record Type in an array

Hi all,

I have a question on the below coding which I could not figure out. I have to enter the Instructor ID and invokes getFees to find the fees of the given instructor. Then it will displays the message that shows either the fees or "No such instructor ID" if not found. the function prototype is double.getProfessionFees(string);

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


const int DECLARED_SIZE = 7;
int search(const int a[], int number_used, int target);

 struct InstructorType
 {
 string name;
 char ID;
 float basicFees;
 float discountRate;
 }

 

int main( )
{

 char arr[DECLARED_SIZE] = {S001,S002,S003,S004,S005,S006,S007};
 int list_size = DECLARED_SIZE, target;
 char ans;
 int result;
 char instructor;
 float getFees;

 InstructorType instructor[7];
 instructor[0].name = "Lim Toa Toa";
 instructor[1].name = "Tan Sio Sio";
 instructor[2].name = "Chua Pei Pei";
 instructor[3].name = "Eric Lim Ming Ming";
 instructor[4].name = "Joanna Tan Yu Yu";
 instructor[5].name = "Sim Wee wee";
 instructor[6].name = "Bella Tan Bell Bell";

 struct point
{
	int xco;
	int yco;
};

point polygon[5];

polygon[0].xco = 0;
polygon[0].yco = 0;
polygon[2].xco = 10;
polygon[2].yco = 20;

getFees = basicFees - discountRate * basicFees;
 do
 {
 cout << "Enter an Instructor ID to search for: ";
 cin >> target;
 result = search(arr, list_size, target);
 if (result == -1)
 cout << target << " is not on the list.\n";
 else
 cout << target << " is "
 << instructor.name << "with fees of" << getFees << endl;
 cout << "Search again?(y/n followed by Return): ";
 cin >> ans;
 }while ((ans != 'n') && (ans != 'N'));
 cout << "End of program.\n";
 return 0;
}
int search(const int a[], int number_used, int target)
{
 int index = 0;
 bool found = false;
 while ((!found) && (index < number_used))
 if (target == a[index])
 found = true;
 else
 index++;
 if (found)
 return index;
 else
 return -1;
}
Last edited on
char arr[DECLARED_SIZE] = {S001,S002,S003,S004,S005,S006,S007};

What are you trying to do here? It doesnt work that way.

it looks like you want a string array. in that case, you need to use quotes.

string arr[DECLARED_SIZE] = {"S001","S002",.....;
Hi I try changing it but it still doesn't work. Sorry, I am a beginner of C++.
You could start by actually answering the question you were asked:

What are you trying to do here?

People don't ask questions because they like the sound of their fingers hitting the keyboard. They ask questions because if we can understand more about your problem, we can help you better.

If you're just going to ignore what people say in your thread, why shouldn't we just ignore you likewise?
Last edited on
I'm trying to do search engine which then to key in the Instructor ID which is the build in the array of S001, S002 .... and S007 which is the instructor ID. Then with the ID it will display the name of the instructor and invokes then display getFees to find the fees of the given instructor getFees = basicFees - discountRate * basicFees.

discountRate will be {10, 20, 30, 40, 50, 60, 70}
basicFees = {100, 200, 300, 400, 500, 600, 700}

Any helpers to access this issue?
Hi anyone can help me to resolve this problem?
So, your instructor ID's are clearly strings, rather than individual characters. So:

- it makes no sense to have it as a one dimensional array of characters. It should be an array of strings.
- the values you populate that array with should be strings, e.g.

[code]{"S001","S002",... } [code]

just as TarikNeaj showed you. Of course, you'll then need to make sure anything that uses that array is using it as the correct type of array, e.g. your search function will need to take the correct type of array.

Beyond that, well... "it still doesn't work" isn't really a very helpful thing to tell us. What errors are you seeing? What lines are causing those errors?
Topic archived. No new replies allowed.