weird error message

Pages: 12
What would be the fun of it if we told you how to do it? You're a programmer, aren't you (or at least, trying to become one)? Figure it out!

EDIT: By the way, I just noticed that your code is hopelessly broken. You don't have any other choice but to start over.
Last edited on
Yeah, I don't mean to be cruel but in general I think you need to code slower and be more careful. A lot of the problems you come up with are easy to spot so you'd be better off:
1) examining your problem carefully without writing a word of code. Figure out how you should do things and try to stick to that in the beginning.
2) Slowly code out your base plan and then test it out. Systematically examine it for errors and read those error messages carefully - they often have easy messages that people overlook. When you make changes examine their impact carefully and change other parts of your prog to compensate.
Repeat step 2 until your code works.
So I'd have to agree with helios. Right about now you'd be best of scrapping your current code and designing something cleaner and more continuous.
ok.
ok so i made a new program but it prints out the result for a second then exits

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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include <stdio.h>
#include "genlib.h"
#include "simpio.h"

#define size 26

char elements(bool A[], bool B[], bool set[]);
void displaySet(bool set[]);
bool unions(bool A[],bool B[],bool C[]);
bool intersection(bool A[],bool B[],bool C[]);
bool contain(bool A[],bool B[]);

typedef enum
{
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
}
letters;
int main()
{
bool set[size];
bool A[size];
bool B[size];
bool C[size];
elements(A, B, set);
unions(A,B,C);
displaySet(C);
intersection(A,B,C);
getchar();
return 0;
}

/*************************************…
/* This function initializes the values for each set. */

char elements(bool A[], bool B[], bool set[])
{
char element;
letters l;
printf("Press enter after each element.\n");
printf("Signal the end of the list by pressing 'ctrl' 'c'.\n");
printf("Enter the first element:");
for(l=a; l<=z;l=(letters)(l+1))
{
set[l]=false;
}
 while((element=getchar())!=EOF)
{
element=element-97;
l=(letters)element;
if(l>=a&&l<=z)
set[l]=true;
}
}

/*************************************…
/* This function displays the values of a set to the output. */


void displaySet(bool set[])
{
letters l;
for(l=a; l<=z; l=(letters)(l+1))
{
if(set[l])
printf("%c", (l+97));
}
}

/*************************************…
/*This function computes the union of sets A and B and puts the value in set C.*/

bool unions(bool A[],bool B[],bool C[])
{
letters letter;
printf("The union of set A and set B = { ");
for(letter=a; letter<=z; letter=(letters)(letter+1))
{
if((A[letter])||(B[letter]))
C[letter]=true;

}
getchar();
return(C);
}

/***********************************in…
/* This function computes the intersection of set A and set B and puts the result
* in set C. */

bool intersection(bool A[],bool B[],bool C[])
{
letters letter;
for(letter=a; letter<=z; letter=(letters)(letter+1))
{
if(A[letter]&&B[letter])
C[letter]=true;
}
getchar();
return(C);
}

/************************************c…
/* This function returns true if B is a proper subset of A and returns false otherwise. */

bool contain(bool A[],bool B[])
{
bool isSubset;
letters letter;
isSubset=true;
for(letter=a; letter<=z; letter=(letters)(letter+1))
{
if(B[letter]&&A[letter])
{
isSubset=true;
A[letter]=false;
B[letter]=false;
}
if(B[letter]&&!A[letter])
isSubset=false; break;
}
if(isSubset)
{
isSubset=false;
for(letter=a; letter<=z; letter=(letters)(letter+1))
{
if(A[letter]&&!B[letter])
isSubset=true;
}
}
getchar();
return(isSubset);
}
Last edited on
Do you expect someone to read that?

Indent your code...
ok I indented my 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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include <stdio.h>
#include "genlib.h"
#include "simpio.h"

#define size 26

char elements(bool A[], bool B, bool set[]);
void displaySet(bool set[]);
bool unions(bool A[],bool B[],bool C[]);
bool intersection(bool A[],bool B[],bool C[]);
bool contain(bool A[],bool B[]);

typedef enum
{
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
}
letters;
int main()
{
    bool set[size];
    bool A[size];
    bool B[size];
    bool C[size];
    elements(A, B, set);
    unions(A,B,C);
    displaySet(C);
    intersection(A,B,C);
    getchar();
    return 0;
}

/*************************************…
/* This function initializes the values for each set. */

char elements(bool A[], bool B, bool set[])
{
     int i;
     char element;
     letters l;
     printf("enter .\n");
     printf("Enter the first element:");
     for(l=a; l<=z;l=(letters)(l+1))
     {
              set[l]=false;
     }
     for (i=0; i<size; i++)
     {
         element=getchar();
         element=element-97;
         l=(letters)element;
         if(l>=a&&l<=z)
         {
                       set[l]=true;
         }
     }
}
/*************************************…
/* This function displays the values of a set to the output. */


void displaySet(bool set[])
{
     letters l;
     for(l=a; l<=z; l=(letters)(l+1))
     {
              if(set[l])
              {
                        printf("%c", (l+97));
              }
     }
}

/*************************************…
/*This function computes the union of sets A and B and puts the value in set C.*/

bool unions(bool A[],bool B[],bool C[])
{
     letters letter;
     char ch;

     for(letter=a; letter<=z; letter=(letters)(letter+1))
     {
                   if((A[letter])||(B[letter]))
                   {
                                               C[letter]=true;
                   }
     }
     printf("The union of set A and set B = { ");
     ch = C[letter];
     printf("%c, ", ch);
     getchar();
}

/***********************************in…
/* This function computes the intersection of set A and set B and puts the result
* in set C. */

bool intersection(bool A[],bool B[],bool C[])
{
     letters letter;
     char ch;
     for(letter=a; letter<=z; letter=(letters)(letter+1))
     {
                   if(A[letter]&&B[letter])
                   {
                                           C[letter]=true;
                   }
     }
     ch=C[letter];
     printf("%c, ", ch);
     getchar();
}

/************************************c…
/* This function returns true if B is a proper subset of A and returns false otherwise. */

bool contain(bool A[],bool B[])
{
     bool isSubset;
     letters letter;
     isSubset=true;
     for(letter=a; letter<=z; letter=(letters)(letter+1))
     {
                   if(B[letter]&&A[letter])
                   {
                                           isSubset=true;
                                           A[letter]=false;
                                           B[letter]=false;
                   }
                   if(B[letter]&&!A[letter])
                   {
                                            isSubset=false; 
                                            break;
                   }
     }
     if(isSubset)
     {
                 isSubset=false;
                 for(letter=a; letter<=z; letter=(letters)(letter+1))
                 {
                               if(A[letter]&&!B[letter])
                               {
                                                        isSubset=true;
                               }
                 }
     }
     return (isSubset);
     getchar();
}
Despite my pains I shall go about pointing out the errors.
First of all you misinterpret enum again. Enum is not preceded by typedef. In a way, it is a typedef. You don't say this:
typedef class myclass;
You say this:
class myclass;
Same deal with enum. I pointed you to that documentation (http://www.cplusplus.com/doc/tutorial/other_data_types/) and I'm gonna say it again: this is how you do an enumeration.
enum THENAMEOFYOURENUM {THEVALUESOFYOURENUM, MOREVALUES, ETC};

I'm truly glad you tried my ascii-shift print idea. I hope it works.
I'm not entirely sure what you did with contain but I'm pretty sure it works.
Anyway nice stuff. This code is much better than the stuff you had before. If you haven't tested it yet, do so and see how it goes (accounting for that one enum issue of course).
im almost done with my program however, im getting this strange error
no match for 'operator++' in '++letter'


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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <stdio.h>
#include "genlib.h"
#include "simpio.h"

#define size 26


void displaySet(bool set[]);
bool unions(bool A[],bool B[],bool C[]);
bool intersection(bool A[],bool B[],bool C[]);
bool contain(bool A[],bool B[]);
enum letters
{
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
};
int main()
{
    bool A[size];
    bool B[size];
    bool C[size];
    displaySet(C);
    printf("This is a test.\n");
    getchar();
    unions(A,B,C);
    displaySet(C);
    getchar();
    intersection(A,B,C);
    displaySet(C);
    contain(A,B);
    getchar();
    return 0;
}
void displaySet(bool set[])
{
     letters l;
     for(l=a; l<=z; l=(letters)(l+1))
     {
              if(set[l])
              {
                        printf("%c", (l+97));
              }
     }
     printf("\n");
}
bool unions(bool A[],bool B[],bool C[])
{
     letters letter;
     printf("The union of sets A and B is: ");
     for(letter=a; letter<=z; letter=(letters)(letter+1))
     {    
          if((A[letter])||(B[letter]))
          {
                                      C[letter]=true;
          }
     }
     return(C);
}
bool intersection(bool A[],bool B[],bool C[])
{
     char ch;
     letters letter;
      printf("The intersect of sets A and B is: ");
     for(letter=a; letter<=z; letter=(letters)(letter+1))
     {
                   if(A[letter]&&B[letter])
                   {
                   C[letter]=true;
                   }
     }
     return (C);
}
bool contain(bool A[], bool B[])
{
     bool isSubset;
     letters letter;
     isSubset=true;
     for (letter=a; letter<=z; letter++)
     {
         if (B[letter] && A[letter])
         {
                       isSubset=true;
                       A[letter]=false;
                       B[letter]=false;
         }
         if (B[letter] && !A[letter])
         {
                       isSubset=false;
                       break;
         }
     }
     if (isSubset == true)
     {
                  printf("\nTRUE");
     }
     else 
     {
          printf("\nFALSE");
     }
}
It's exactly as it says, the increment operator is not overloaded for your letter enum. Try casting to int first; even though enum is really just a wrapper of an integer it probably won't respond too well to that incrementing.
Ok the error is gone. However, the contain() function is not returning the right answer.

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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <stdio.h>
#include "genlib.h"
#include "simpio.h"

#define size 26


void displaySet(bool set[]);
bool unions(bool A[],bool B[],bool C[]);
bool intersection(bool A[],bool B[],bool C[]);
bool contain(bool A[],bool B[]);
enum letters
{
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z
};
int main()
{
    bool A[size];
    bool B[size];
    bool C[size];
    displaySet(C);
    printf("This is a test.\n");
    getchar();
    unions(A,B,C);
    displaySet(C);
    getchar();
    intersection(A,B,C);
    displaySet(C);
    contain(A,B);
    getchar();
    return 0;
}
void displaySet(bool set[])
{
     letters l;
     for(l=a; l<=z; l=(letters)(l+1))
     {
              if(set[l])
              {
                        printf("%c", (l+97));
              }
     }
     printf("\n");
}
bool unions(bool A[],bool B[],bool C[])
{
     letters letter;
     printf("The union of sets A and B is: ");
     for(letter=a; letter<=z; letter=(letters)(letter+1))
     {    
          if((A[letter])||(B[letter]))
          {
                                      C[letter]=true;
          }
     }
     return(C);
}
bool intersection(bool A[],bool B[],bool C[])
{
     char ch;
     letters letter;
      printf("The intersect of sets A and B is: ");
     for(letter=a; letter<=z; letter=(letters)(letter+1))
     {
                   if(A[letter]&&B[letter])
                   {
                   C[letter]=true;
                   }
     }
     return (C);
}
bool contain(bool A[], bool B[])
{
     bool isSubset;
    int letter;
     isSubset=true;
     for (letter=a; letter<=z; letter=(letters)(letter+1))
     {
         if (B[letter] && A[letter])
         {
                       isSubset=true;
                       A[letter]=false;
                       B[letter]=false;
         }
         if (B[letter] && !A[letter])
         {
                       isSubset=false;
                       break;
         }
     }
     if (isSubset == true)
     {
                  printf("\nTRUE");
     }
     else 
     {
          printf("\nFALSE");
     }
}
I don't even see it returning anything.
Well it's always returning false for some reason.
Well then where are the return statements?
i figured it out. And thanks for helping.
Topic archived. No new replies allowed.
Pages: 12