Pointers and Structures



i
Last edited on

line 19: loop for : delete <= 10 and change with < 10;

point & cls is two arrays with 10 items from 0 to 9 ;
Last edited on
Thanks that fixed the issue of it repeating the menu but now whenever I select '1' it gives me an error?


change with add( *cls ) ;
Last edited on
On what line?

line 29...
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
#include <iostream>
#include <cstring>
using namespace std;

struct Class {
	char title[50];
	int units;
	char grade;
};
void menu();
int add(struct Class** ptr);
int main()
{
	char choice;
	Class* ptr[10] = {0};
	do
	{
		menu();
		cin >> choice;
		if (choice == '1')
			add(ptr);
		else if (choice == '2')
			cout << "choice works" << endl; 
		else if (choice == '3')
			cout << "choice works" << endl; 
		else if (choice == '4')
			cout << "choice works" << endl; 
		else if (choice == '5')
			cout << "choice works" << endl;
		else if (choice == '6')
			cout << "choice works" << endl; 
		else if (choice == '7')
		{
			cout << "quitting...." << endl;
			choice = 7;
		}
		else
			cout << "invalid input" << endl;

	} while (choice != 7);
}
void menu()
{
	cout << "1. Add new class." << endl;
	cout << "2. Edit an existing class" << endl;
	cout << "3. Display a class" << endl;
	cout << "4. List all classes " << endl;
	cout << "5. Display GPA" << endl;
	cout << "6. Delete all classes" << endl;
	cout << "7. Quit." << endl;
}

int add(Class** ptr[])
{

		ptr[i] = new Class;
		cout << "Enter class name: ";
		cin >> ptr[i].title;
		cout << "Enter number of units: ";
		cin >> ptr[i].units;
		cout << "Enter grade recived: ";
		cin >> ptr[i].grade;
	}
}


I changed it up a bit

The teacher asks to do this for the add function:
"If Add new class is selected, pass the array of pointers to an add() function, which dynamically allocates memory for a new Class, reads the class information (title, units and grade) from the user, saves its pointer in the array of pointers and displays the menu again."

I did what he said but I get errors?
OP: if you deleted your original post then it's difficult to put everything following it in context
Topic archived. No new replies allowed.