question

hello, i dont know why the delet fun dosent run!!
please need your help.

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

class su{
public:
	string Sub;
	static int idofsub;
	subscription *sub[10];
	
public:

	sub(string s="subsriber",int n=10){ Sub=s; }
	static int getid() { return idofsub++; }
   void setSub(string Subb){Subb=Sub;}
	string getSub()const{return Sub;}
	
	
	void add_Sub()
	{
	
		int chose;
		char answer;
		cout << "ADD NEW MEMBER" <<endl;
		cout << "Do you want to add a new member ? (yes,no)" <<endl;
		cin >> answer;
		
		do {
			if ( answer == 'y' ){
				cout << "What is your name ? " <<endl;
				cin >> Subscription;
				cout << "Your ID is : "<<getid() <<endl;
				setSubscription(Subscription);

cout << "Now the member is included in the subscription ofmy pet" <<endl<<endl; subscription ob(Subscription,getid());
 for(int i=0;i<10;i++){
 sub[i]=&ob;
 else
 cout << " Thank you, Come again" <<endl; 
}
}
cout << "If you want another new subscription press 1, if you're not press 0 " <<endl;
cin >> chose;
} while (chose!=0 );
}
void delet_Subscription(){
string nameofSubscription;
cout << "DELETE Subscription" <<endl;
cout << "What is your name ? " <<endl;
cin >> nameofSubscription;
	for(int i=0;i<10;i++){
	if(sub[i]->getSubscription()==nameofSubscription){
	delete sub[i]; 
	sub[i]=NULL;
	}else
		cout<<"is not delet it \n";
	}
cout<<"the animal is deleted"<<endl;
}
	void showtheSubscription()
	{
		cout << "SHOW the Subscription" <<endl;
		for(int i=0;i<50;i++){
			if(sub[i]!=0){
			 cout<<"the name member is :"<<sub[i]->getSubscription(); }
			else
			{ cout<<"that set:)"<<endl; }
		}
	 }	 
};
int subscription::idofSubscription=1;

int main(){
subscription obj("none",10);
obj.add_Subscription();
cout<<endl;
obj.delet_Subscription();
cout<<endl;

system("pause");
return 0;
}
closed account (2LzbRXSz)
As soon as I popped it into Xcode I got ten whole error messages, so let's take it one by one:)

subscription *sub[10]; subscription is an unknown type name. Did you mean su?

sub(string s="subsriber",int n=10){ Sub=s; }
Same problem here - you haven't defined sub as an identifier. I'm going to assume you mean su again.

cin >> Subscription; setSubscription(Subscription); subscription ob(Subscription,getid()); Subscription isn't defined.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
do {
            if ( answer == 'y' ){
                cout << "What is your name ? " <<endl;
                cin >> Subscription;
                cout << "Your ID is : "<<getid() <<endl;
                setSubscription(Subscription);
                
                cout << "Now the member is included in the subscription ofmy pet" <<endl<<endl; subscription ob(Subscription,getid());
                for(int i=0;i<10;i++){
                    sub[i]=&ob;
                else
                        cout << " Thank you, Come again" <<endl;
                }
            }
            cout << "If you want another new subscription press 1, if you're not press 0 " <<endl;
            cin >> chose;
        } while (chose!=0 );
    }

This whole area is sort of jumbled up. Your if and for loop are missing closing curly brackets.
Your do while loop also got mixed up. This whole area is sort of a mess really.

if(sub[i]->getSubscription()==nameofSubscription){
sub should be su, but there's multiple errors I'm getting for this line alone.

delete sub[i];
My compiler said to turn it to su::sub, but that just gave me more errors.

I can try my best to help you clean this up, but I'll need your help too since I am kind of confused about what you're trying to do and what's going on. Are you using an IDE or a debugger?
Last edited on
Topic archived. No new replies allowed.