Undefined symbol error in Turbo C++

Pages: 123
I want to create a GK Quiz project named Infinite Knowledge. In this I created a C++ Class 'Quiz' with the following members given. I haven't yet completed the whole coding but when I compiled ( whatever I've written till now ), in Turbo C++ I get errors like:

Error IK.CPP 52: Undefined symbol 'choice'
Error IK.CPP 86: Undefined symbol 'ch1'
Error IK.CPP 113: Undefined symbol 'ch2'
Error IK.CPP 143: Undefined symbol 'ch3'
Error IK.CPP 164: Undefined symbol 'userName'
Error IK.CPP 167: Undefined symbol 'LChoice'
Error IK.CPP 173: Undefined symbol 'TChoice'
The code is given here:

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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//The Infinite Knowledge Quiz Program
#include<iostream.h>
#include<conio.h>
#include<process.h>
class Quiz
{char userName[30];
char ques, lChoice, tChoice, ans, userAns, choice, ch1, ch2, ch3;
int score;
public:
void quizComp();
void dispScore();
void highScore();
void about();
void legal();
void help();
void start();
void bScience();
void bArts();
void bEnt();
void bGeo();
void bInd;
void bLang();
void bSports();
void iScience();
void iArts();
void iEnt();
void iGeo();
void iInd;
void iLang();
void iSports();
void eScience();
void eArts();
void eEnt();
void eGeo();
void eInd;
void eLang();
void eSports();
};

void main()
{clrscr();
getch();
cout<<"               *          *   *";
cout<<"               *          * *  ";
cout<<"               *          **   ";
cout<<"               *          * *  ";
cout<<"               *          *   *";
cout<<"\n\n\n Welcome to INFINITE KNOWLEDGE, the most interactive DOS-based quiz";
cout<<"\n ever. This will surely sharpen your skills on the topics which you select.";
cout<<"\n\n So, go ahead and reach your milestone!";
cout<<"\n\n\n\n\n Press 'A' for About, 'L' for Legal, 'H' for Help, 'HS' for Highest Scores and 'S' to Start:";
cin>>choice;
if ((choice=='A')||(choice=='a'))
{clrscr();
void about();}
else if((choice=='L')||(choice=='l'))
{clrscr();
void legal();}
else if((choice=='H')||(choice=='h'))
{clrscr();
void help();}
else if((choice=='S')||(choice=='s'))
{clrscr();
void start();}
else
{cout<<"\n Wrong choice...EXITING!!";
exit(0);}
Quiz Q1;
Q1.about();
Q1.legal();
Q1.help();
Q1.start();}

void about()
{cout<<" *  *  *  *  *  *  *  *  *  *     *  *  *  * ";
cout<<"  *     *  *     *  *     *  *     *     *    ";
cout<<"  *  *  *  *  *  *  *     *  *     *     *    ";
cout<<"  *     *  *     *  *     *  *     *     *    ";
cout<<"  *     *  *  *  *  *  *  *  *  *  *     *    ";
cout<<"\n\n\n INFINITE KNOWLEDGE is an interactive application quiz based on the recent affairs";
cout<<"\n , history of world, sceinces, computers, english and much more.";
cout<<"\n Developed to test how much you know of your selection, this'll be a great help for all in future.";
cout<<"\n See the interrorgation, analyse it and if you're sure then only move ahead";
cout<<"\n or if you fail for an answer don't worry, we'll provide you. And yes, there are explanations also!";
cout<<"\n\n\n\n\n Press 'L' for Legal, 'H' for Help, 'HS' for Highest Scores and 'S' to Start:";
cin>>ch1;
if((ch1=='L')||(ch1=='l'))
{clrscr();
void legal();}
if((ch1=='H')||(ch1=='h'))
{clrscr();
void help();}
else if((ch1=='S')||(ch1=='s'))
{clrscr();
void start();}
else
{cout<<"n Wrong choice...EXITING!!";
exit(0);}}

void legal()
{cout<<"  *         *  *  *   *  *  *   *  *  *   *       ";
cout<<"   *         *         *         *     *   *       ";
cout<<"   *         *  *      *  *  *   *  *  *   *       ";
cout<<"   *         *         *     *   *     *   *       ";
cout<<"   *  *  *   *  *  *   *  *  *   *     *   *  *  * ";
cout<<"\n\n\n Developed by : VAIBHAV KHULBE with ROHAN SHARMA";
cout<<"\n\n Roll No(s) : 12140 and 1213  ";
cout<<"\n\n Class and Section : XII - A";
cout<<"\n\n Last modified on :  /  / 14";
cout<<"\n\n Questions taken from : 'INFINITE KNOWLEDGE - A Quiz Book' by VAIBHAV KHULBE and PRATEEK LIDHOO";
cout<<"\n\n (c) 2014 Developers and Authors";
cout<<"\n\n Press 'A' for About, 'H' for Help, 'HS' for Highest Scores and 'S' to Start:";
cin>>ch2;
if((ch2=='A')||(ch2=='a'))
{clrscr();
void about();}
else if((ch2=='H')||(ch2=='h'))
{clrscr();
void help();}
else if((ch2=='S')||(ch2=='s'))
{clrscr();
void start();}
else if((ch2=='HS')||(ch2=='hs'))
{clrscr();
void highScore();}
else
{cout<<"n Wrong choice...EXITING!!";
exit(0);}}

void help()
{clrscr();
cout<<"  *      *   *  *  *   *        *  *  * ";
cout<<"  *      *   *         *        *     * ";
cout<<"  *  *   *   *  *      *        *  *  * ";
cout<<"  *      *   *         *        *       ";
cout<<"  *      *   *  *  *   *  *  *  *       ";
cout<<"\n\n\n We believe there isn't any need of HELP for you.";
cout<<"\n This is the most simlplest quiz made intuitively for everyone.";
cout<<"\n We'll provide you with extra hints as you give us the answers.";
cout<<"\n For that all you need to do is to choose an option from the four alternatives : 'a', 'b', 'c' or 'd'!";
cout<<"\n\n\n GO AHEAD!";
cout<<"\n\n\n Press 'A' for About, 'L' for Legal, 'HS' for Highest Scores and 'S' to Start:";
cin>>ch3;
if((ch3=='A')||(ch3=='a'))
{clrscr();
void about();}

else if((ch3=='S')||(ch3=='s'))
{clrscr();
void start();}
else if((ch3=='HS')||(ch3=='hs'))
{clrscr();
void highScore();}
else if((ch3=='L')||(ch3=='l'))
{clrscr();
void legal();}
else
{cout<<"n Wrong choice...EXITING!!";
exit(0);}}

void start()
{clrscr();
cout<<"\n How should we call you? :";
cin>>userName;
cout<<"\n"<<userName<<" Choose a Level : Beginner \t Intermediate \t Expert";
cout<<"\n Press 'B' for Beginner, 'I' for Intermediate or 'E' for Expert:";
cin>>Lchoice;

{if((Lchoice=='B')||(Lchoice=='b'))
{cout<<userName<<" In which of the following topics you're interested in?";
cout<<"\n 'S'ciences, 'A'rts, 'E'ntertainment, 'G'eography, 'I'ndia, 'L'anguage and Literature or 'S'ports";
cout<<"\n Enter the letter inside the inverted commas of your selection:";
cin>>Tchoice;
cout<<userName<<" you opted for "<<Tchoice<<" in Beginner level";
cout<<"\n Next 10 questions will check your knowledge on "<<Tchoice;
cout<<"\n If you're ready then press enter...";
clrscr();
}void bScience();}}


Can someone provide me with any help?
Well, I have a question to ask, as a starting point:

Why the hell are you doing this in Turbo C++? Not to be rude, but... the website for it doesn't even work anymore.
Last edited on

Well, I have a question to ask, as a starting point:

Why the hell are you doing this in Turbo C++? Not to be rude, but... the website for it doesn't even work anymore.


I've heard from some friends from India that a bunch of schools there use really out-of-date compilers like Turbo C/C++.

I'm not sure where this guy is from, but maybe it's the same situation.
Last edited on
Line 4: You need using namespace std; Turbo C/C++ probably doesn't require this, but current C++ compilers (which you should be using) do require it if you don't qualify your references to the std:: namespace.

Line 21,28,35: Illegal use of void. Did you intend ()? Your compiler didn't even detect this.

Line 52: choice is undefined. You have to define a variable before you can do cin to it. Line 7: choice is a private member of your Quiz class. You can't access it directly from main(). This is the cause of all your undefined variable diagnostics.

Note that each of your functions (help, legal, about, etc) are stand-alone functions. They are not members of your class. If you want to code functions that are members of your class, you need to use the class name in the function definition. e.g. void Quiz::Help ()

Line 55 and too many other places to itemize: When you do a function call, do NOT put the word void in front of the function call.





Last edited on
@OP: choice, ch1, ch2, etc is out of scope... you must use a public function to access the object member.

and, yeah, don't use TC++ that's bad for your health :D
I'm replying to all of your questions:

1. Ispil:

Well, I have a question to ask, as a starting point:

Why the hell are you doing this in Turbo C++? Not to be rude, but... the website for it doesn't even work anymore.


I'm too fed up using Turbo C++ but here we're taught to use this compiler only. Otherwise I also use Microsoft Visual Studio Express editions for making other stuffs..

2. Mechennyy:

I've heard from some friends from India that a bunch of schools there use really out-of-date compilers like Turbo C/C++.

I'm not sure where this guy is from, but maybe it's the same situation.


I'm from India only and we're taught to use Turbo C++ only!

3. AbstractionAnon:

Line 4: You need using namespace std; Turbo C/C++ probably doesn't require this, but current C++ compilers (which you should be using) do require it if you don't qualify your references to the std:: namespace.

Line 21,28,35: Illegal use of void. Did you intend ()? Your compiler didn't even detect this.

Line 52: choice is undefined. You have to define a variable before you can do cin to it. Line 7: choice is a private member of your Quiz class. You can't access it directly from main(). This is the cause of all your undefined variable diagnostics.

Note that each of your functions (help, legal, about, etc) are stand-alone functions. They are not members of your class. If you want to code functions that are members of your class, you need to use the class name in the function definition. e.g. void Quiz::Help ()

Line 55 and too many other places to itemize: When you do a function call, do NOT put the word void in front of the function call.


I don't use using namespace std; maybe because Turbo C++ doesn't require this.

Second, as I've said before, I haven't completed my code. Sorry for not putting () after the bInd, iInd and eInd functions...

Third, help, legal and about all are functions of class Quiz, see lines 13, 14 and 15. I'll try what you suggested
e.g.
void Quiz::Help ()

4. chipp:

@OP: choice, ch1, ch2, etc is out of scope... you must use a public function to access the object member.

and, yeah, don't use TC++ that's bad for your health :D


I've assigned these variables under public: section.
If you're going to post on this site, you're going to get help relevant to a standards compiliant C++ compiler. In other words, Turbo C++ does not comply with even the C++2003 standard.

As for namespaces, namespaces were introduced in 1998. If Turbo C++ does not support namespaces, that is how out of date your compiler is.

The OP has already stated that he doesn't have a choice for which compiler to use. And since this is cplusplus.com and not C++11.com or C++14.com, I for one am willing to help.

The big problem here is that you have all the data in member variables but then code is all in global functions. Some of this data should be in local variables.

Your main(), help(), legal() and about() functions all contain code to prompt the user for the same action. That code should all be in main().
@dhayden - In my first post, I provided several items of help without reference to Turbo C++. It was only when the OP made excuses for not using using namespace or qualifying library references with std::, that I brought up the issue of an obsolete compiler.

@OP - Your instructor is not doing you any favors by requiring you to use an obsolete compiler. You should complain to him and to your school that you are being taught using information and methods that are 20 years out of date in a rapidly changing field (well okay, maybe the ANSI committee doesn't move rapidly), but you get my point.

AbstractionAnon :

If you're going to post on this site, you're going to get help relevant to a standards compiliant C++ compiler. In other words, Turbo C++ does not comply with even the C++2003 standard.

As for namespaces, namespaces were introduced in 1998. If Turbo C++ does not support namespaces, that is how out of date your compiler is.



Well I know that my compiler it too out-dated.

dhayden :

The OP has already stated that he doesn't have a choice for which compiler to use. And since this is cplusplus.com and not C++11.com or C++14.com, I for one am willing to help.

The big problem here is that you have all the data in member variables but then code is all in global functions. Some of this data should be in local variables.

Your main(), help(), legal() and about() functions all contain code to prompt the user for the same action. That code should all be in main().


I've updated the as you suggested:

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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
//The Infinite Knowledge Quiz Program
#include<iostream.h>
#include<conio.h>
#include<process.h>
class Quiz
{char userName[30];
int score;
public:
char ques, lChoice, tChoice, ans, userAns, choice, ch1, ch2, ch3;
void quizComp();
void dispScore();
void highScore();
void about();
void legal();
void help();
void start();
void bScience();
void bArts();
void bEnt();
void bGeo();
void bInd();
void bLang();
void bSports();
void iScience();
void iArts();
void iEnt();
void iGeo();
void iInd();
void iLang();
void iSports();
void eScience();
void eArts();
void eEnt();
void eGeo();
void eInd();
void eLang();
void eSports();
};

void main()
{clrscr();
getch();
cout<<"               *          *   *";
cout<<"               *          * *  ";
cout<<"               *          **   ";
cout<<"               *          * *  ";
cout<<"               *          *   *";
cout<<"\n\n\n Welcome to INFINITE KNOWLEDGE, the most interactive DOS-based quiz";
cout<<"\n ever. This will surely sharpen your skills on the topics which you select.";
cout<<"\n\n So, go ahead and reach your milestone!";
cout<<"\n\n\n\n\n Press 'A' for About, 'L' for Legal, 'H' for Help, 'HS' for Highest Scores and 'S' to Start:";
cin>>choice;
if ((choice=='A')||(choice=='a'))
{clrscr();
about();}
else if((choice=='L')||(choice=='l'))
{clrscr();
legal();}
else if((choice=='H')||(choice=='h'))
{clrscr();
help();}
else if((choice=='S')||(choice=='s'))
{clrscr();
start();}
else
{cout<<"\n Wrong choice...EXITING!!";
exit(0);}

void about()
{cout<<" *  *  *  *  *  *  *  *  *  *     *  *  *  * ";
cout<<"  *     *  *     *  *     *  *     *     *    ";
cout<<"  *  *  *  *  *  *  *     *  *     *     *    ";
cout<<"  *     *  *     *  *     *  *     *     *    ";
cout<<"  *     *  *  *  *  *  *  *  *  *  *     *    ";
cout<<"\n\n\n INFINITE KNOWLEDGE is an interactive application quiz based on the recent affairs";
cout<<"\n , history of world, sceinces, computers, english and much more.";
cout<<"\n Developed to test how much you know of your selection, this'll be a great help for all in future.";
cout<<"\n See the interrorgation, analyse it and if you're sure then only move ahead";
cout<<"\n or if you fail for an answer don't worry, we'll provide you. And yes, there are explanations also!";
cout<<"\n\n\n\n\n Press 'L' for Legal, 'H' for Help, 'HS' for Highest Scores and 'S' to Start:";
cin>>ch1;
if((ch1=='L')||(ch1=='l'))
{clrscr();
legal();}
if((ch1=='H')||(ch1=='h'))
{clrscr();
help();}
else if((ch1=='S')||(ch1=='s'))
{clrscr();
start();}
else
{cout<<"n Wrong choice...EXITING!!";
exit(0);}}

void legal()
{cout<<"  *         *  *  *   *  *  *   *  *  *   *       ";
cout<<"   *         *         *         *     *   *       ";
cout<<"   *         *  *      *  *  *   *  *  *   *       ";
cout<<"   *         *         *     *   *     *   *       ";
cout<<"   *  *  *   *  *  *   *  *  *   *     *   *  *  * ";
cout<<"\n\n\n Developed by : VAIBHAV KHULBE with ROHAN SHARMA";
cout<<"\n\n Roll No(s) : 12140 and 1213  ";
cout<<"\n\n Class and Section : XII - A";
cout<<"\n\n Last modified on :  /  / 14";
cout<<"\n\n Questions taken from : 'INFINITE KNOWLEDGE - A Quiz Book' by VAIBHAV KHULBE and PRATEEK LIDHOO";
cout<<"\n\n (c) 2014 Developers and Authors";
cout<<"\n\n Press 'A' for About, 'H' for Help, 'HS' for Highest Scores and 'S' to Start:";
cin>>ch2;
if((ch2=='A')||(ch2=='a'))
{clrscr();
about();}
else if((ch2=='H')||(ch2=='h'))
{clrscr();
help();}
else if((ch2=='S')||(ch2=='s'))
{clrscr();
start();}
else if((ch2=='HS')||(ch2=='hs'))
{clrscr();
highScore();}
else
{cout<<"n Wrong choice...EXITING!!";
exit(0);}}

void help()
{clrscr();
cout<<"  *      *   *  *  *   *        *  *  * ";
cout<<"  *      *   *         *        *     * ";
cout<<"  *  *   *   *  *      *        *  *  * ";
cout<<"  *      *   *         *        *       ";
cout<<"  *      *   *  *  *   *  *  *  *       ";
cout<<"\n\n\n We believe there isn't any need of HELP for you.";
cout<<"\n This is the most simlplest quiz made intuitively for everyone.";
cout<<"\n We'll provide you with extra hints as you give us the answers.";
cout<<"\n For that all you need to do is to choose an option from the four alternatives : 'a', 'b', 'c' or 'd'!";
cout<<"\n\n\n GO AHEAD!";
cout<<"\n\n\n Press 'A' for About, 'L' for Legal, 'HS' for Highest Scores and 'S' to Start:";
cin>>ch3;
if((ch3=='A')||(ch3=='a'))
{clrscr();
about();}

else if((ch3=='S')||(ch3=='s'))
{clrscr();
start();}
else if((ch3=='HS')||(ch3=='hs'))
{clrscr();
highScore();}
else if((ch3=='L')||(ch3=='l'))
{clrscr();
legal();}
else
{cout<<"n Wrong choice...EXITING!!";
exit(0);}}

Quiz Q1;
Q1.about();
Q1.legal();
Q1.help();
Q1.start();}

void Quiz::start()
{clrscr();
cout<<"\n How should we call you? :";
cin>>userName;
cout<<"\n"<<userName<<" Choose a Level : Beginner \t Intermediate \t Expert";
cout<<"\n Press 'B' for Beginner, 'I' for Intermediate or 'E' for Expert:";
cin>>lchoice;

{if((lchoice=='B')||(lchoice=='b'))
{cout<<userName<<" In which of the following topics you're interested in?";
cout<<"\n 'S'ciences, 'A'rts, 'E'ntertainment, 'G'eography, 'I'ndia, 'L'anguage and Literature or 'S'ports";
cout<<"\n Enter the letter inside the inverted commas of your selection:";
cin>>tchoice;
cout<<userName<<" you opted for "<<tchoice<<" in Beginner level";
cout<<"\n Next 10 questions will check your knowledge on "<<tchoice;
cout<<"\n If you're ready then press enter...";
clrscr();
}bScience();}}


Still I'm having some errors:

1. Undefined symbol 'choice'.
2. Function 'about', 'legal' , 'help' and 'start' should have a prototype in lines 55, 58, 61 and 64 respectively.
3. Type mismatch in re declaration of 'about()' in line 70.
4. Declaration syntax error in line 70 on 'cout'.
5. Undefined symbol 'Q1' , 'lChoice' and 'tChoice' in lines 157, 168 and 174 respectively.

Provide any further help...
Line 3: Why are you including process.h?

Line 9: making these variables public is poor style.

1) Line 52, et al: choice is a public member of Quiz. If you want to reference it here, you need to reference an instance of Quiz. e.g. q1.choice. However, better style would have been to make choice a local variable inside main. It's not used outside of main and serves no purpose as a member of Quiz. Note: main has no instance of Quiz.

line 68: You're missing a } to terminate main(). If you used any kind of indentation, this would have been obvious.

2) Line 69, 95, 125: about(), legal() and help() are global functions, not members of your class. However, you've declared them as members at lines 13-15. about, legal and help need to be prefixed by Quiz:: I pointed this out to you previously.
1
2
3
4
5
6
// line 69
void Quiz::about()
// line 95
void Quiz::legal()
// line 125
void Quiz::help()


3,4) These errors are caused by the missing } at the end of main.

5) Lines 156-160: These lines are not part of any function. Where do they belong? Shouldn't they be in main()?

Lines 55,58,61,64: You're calling global functions, but they've not been defined with function prototypes. You seem confused as to whether help(), about(), legal() and start() are global functions or members of your class. If they're global functions, they need function prototypes (and get rid of lines 13-16) or if they're members of your class, they need to be called through an instance of Quiz. Make up your mind.

Line 168,174: The capitialization of lchoice and tchoice does not match line 9.

You declare highScore() and bScience() as member functions, but you have not implemented these function.s However, you attempt to call these functions. This will result in linker errors.
Last edited on
Here's a version of your program with reasonable indentation that compiles and runs:
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
//The Infinite Knowledge Quiz Program
#include<iostream>
#include<conio.h>
using namespace std;
void clrscr ()  // Not a standard function
{}

class Quiz
{   char userName[30];
    int score;
public:
    void quizComp();
    void dispScore();
    //  void highScore();
    void about();
    void legal();
    void help();
    void start();
    void bScience();
    void bArts();
    void bEnt();
    void bGeo();
    void bInd();
    void bLang();
    void bSports();
    void iScience();
    void iArts();
    void iEnt();
    void iGeo();
    void iInd();
    void iLang();
    void iSports();
    void eScience();
    void eArts();
    void eEnt();
    void eGeo();
    void eInd();
    void eLang();
    void eSports();
};

void main()
{   char    choice;
    Quiz    q1;

    clrscr();
    cout<<"               *          *   *";
    cout<<"               *          * *  ";
    cout<<"               *          **   ";
    cout<<"               *          * *  ";
    cout<<"               *          *   *";
    cout<<"\n\n\n Welcome to INFINITE KNOWLEDGE, the most interactive DOS-based quiz";
    cout<<"\n ever. This will surely sharpen your skills on the topics which you select.";
    cout<<"\n\n So, go ahead and reach your milestone!";
    cout<<"\n\n\n\n\n Press 'A' for About, 'L' for Legal, 'H' for Help, 'HS' for Highest Scores and 'S' to Start:";
    cin>>choice;
    if ((choice=='A')||(choice=='a'))
    {   clrscr();
        q1.about();
    }
    else if((choice=='L')||(choice=='l'))
    {   clrscr();
        q1.legal();
    }
    else if((choice=='H')||(choice=='h'))
    {   clrscr();
        q1.help();
    }
    else if((choice=='S')||(choice=='s'))
    {   clrscr();
        q1.start();}
    else
    {   cout<<"\n Wrong choice...EXITING!!";
        exit(0);
    }
    q1.start();
}

void Quiz::about()
{   char ch1;

    cout<<" *  *  *  *  *  *  *  *  *  *     *  *  *  * ";
    cout<<"  *     *  *     *  *     *  *     *     *    ";
    cout<<"  *  *  *  *  *  *  *     *  *     *     *    ";
    cout<<"  *     *  *     *  *     *  *     *     *    ";
    cout<<"  *     *  *  *  *  *  *  *  *  *  *     *    ";
    cout<<"\n\n\n INFINITE KNOWLEDGE is an interactive application quiz based on the recent affairs";
    cout<<"\n , history of world, sceinces, computers, english and much more.";
    cout<<"\n Developed to test how much you know of your selection, this'll be a great help for all in future.";
    cout<<"\n See the interrorgation, analyse it and if you're sure then only move ahead";
    cout<<"\n or if you fail for an answer don't worry, we'll provide you. And yes, there are explanations also!";
    cout<<"\n\n\n\n\n Press 'L' for Legal, 'H' for Help, 'HS' for Highest Scores and 'S' to Start:";
    cin>>ch1;
    if((ch1=='L')||(ch1=='l'))
    {   clrscr();
        legal();
    }
    if((ch1=='H')||(ch1=='h'))
    {   clrscr();
        help();
    }
    else if((ch1=='S')||(ch1=='s'))
    {   clrscr();
        start();
    }
    else
    {   cout<<"n Wrong choice...EXITING!!";
        exit(0);
    }
    system ("pause");
}

void Quiz::legal()
{   char ch2;

    cout<<"  *         *  *  *   *  *  *   *  *  *   *       ";
    cout<<"   *         *         *         *     *   *       ";
    cout<<"   *         *  *      *  *  *   *  *  *   *       ";
    cout<<"   *         *         *     *   *     *   *       ";
    cout<<"   *  *  *   *  *  *   *  *  *   *     *   *  *  * ";
    cout<<"\n\n\n Developed by : VAIBHAV KHULBE with ROHAN SHARMA";
    cout<<"\n\n Roll No(s) : 12140 and 1213  ";
    cout<<"\n\n Class and Section : XII - A";
    cout<<"\n\n Last modified on :  /  / 14";
    cout<<"\n\n Questions taken from : 'INFINITE KNOWLEDGE - A Quiz Book' by VAIBHAV KHULBE and PRATEEK LIDHOO";
    cout<<"\n\n (c) 2014 Developers and Authors";
    cout<<"\n\n Press 'A' for About, 'H' for Help, 'HS' for Highest Scores and 'S' to Start:";
    cin>>ch2;
    if((ch2=='A')||(ch2=='a'))
    {   clrscr();
        about();
    }
    else if((ch2=='H')||(ch2=='h'))
    {   clrscr();
        help();
    }
    else if((ch2=='S')||(ch2=='s'))
    {   clrscr();
        start();
    }
    else if((ch2=='HS')||(ch2=='hs'))
    {   clrscr();
        //  highScore();
    }
    else
    {   cout<<"n Wrong choice...EXITING!!";
        exit(0);
    }
}

void Quiz::help()
{   char    ch3;

    clrscr();
    cout<<"  *      *   *  *  *   *        *  *  * ";
    cout<<"  *      *   *         *        *     * ";
    cout<<"  *  *   *   *  *      *        *  *  * ";
    cout<<"  *      *   *         *        *       ";
    cout<<"  *      *   *  *  *   *  *  *  *       ";
    cout<<"\n\n\n We believe there isn't any need of HELP for you.";
    cout<<"\n This is the most simlplest quiz made intuitively for everyone.";
    cout<<"\n We'll provide you with extra hints as you give us the answers.";
    cout<<"\n For that all you need to do is to choose an option from the four alternatives : 'a', 'b', 'c' or 'd'!";
    cout<<"\n\n\n GO AHEAD!";
    cout<<"\n\n\n Press 'A' for About, 'L' for Legal, 'HS' for Highest Scores and 'S' to Start:";
    cin>>ch3;
    if((ch3=='A')||(ch3=='a'))
    {   clrscr();
        about();
    }
    else if((ch3=='S')||(ch3=='s'))
    {   clrscr();
        start();
    }
    else if((ch3=='HS')||(ch3=='hs'))
    {   clrscr();
    //  highScore();
    }
    else if((ch3=='L')||(ch3=='l'))
    {   clrscr();
        legal();
    }
    else
    {   cout<<"n Wrong choice...EXITING!!";
        exit(0);
    }
}

void Quiz::start()
{   char lchoice, tchoice;

    clrscr();
    cout<<"\n How should we call you? :";
    cin>>userName;
    cout<<"\n"<<userName<<" Choose a Level : Beginner \t Intermediate \t Expert";
    cout<<"\n Press 'B' for Beginner, 'I' for Intermediate or 'E' for Expert:";
    cin>>lchoice;

    {   if((lchoice=='B')||(lchoice=='b'))
        {   cout<<userName<<" In which of the following topics you're interested in?";
            cout<<"\n 'S'ciences, 'A'rts, 'E'ntertainment, 'G'eography, 'I'ndia, 'L'anguage and Literature or 'S'ports";
            cout<<"\n Enter the letter inside the inverted commas of your selection:";
            cin>>tchoice;
            cout<<userName<<" you opted for "<<tchoice<<" in Beginner level";
            cout<<"\n Next 10 questions will check your knowledge on "<<tchoice;
            cout<<"\n If you're ready then press enter...";
            clrscr();
        }
    //  bScience();
    }
} 
AbstractionAnon:

Line 3: Why are you including process.h?

Line 9: making these variables public is poor style.

1) Line 52, et al: choice is a public member of Quiz. If you want to reference it here, you need to reference an instance of Quiz. e.g. q1.choice. However, better style would have been to make choice a local variable inside main. It's not used outside of main and serves no purpose as a member of Quiz. Note: main has no instance of Quiz.

line 68: You're missing a } to terminate main(). If you used any kind of indentation, this would have been obvious.

2) Line 69, 95, 125: about(), legal() and help() are global functions, not members of your class. However, you've declared them as members at lines 13-15. about, legal and help need to be prefixed by Quiz:: I pointed this out to you previously.

1
2
3
4
5
6
// line 69
void Quiz::about()
// line 95
void Quiz::legal()
// line 125
void Quiz::help()



3,4) These errors are caused by the missing } at the end of main.

5) Lines 156-160: These lines are not part of any function. Where do they belong? Shouldn't they be in main()?

Lines 55,58,61,64: You're calling global functions, but they've not been defined with function prototypes. You seem confused as to whether help(), about(), legal() and start() are global functions or members of your class. If they're global functions, they need function prototypes (and get rid of lines 13-16) or if they're members of your class, they need to be called through an instance of Quiz. Make up your mind.

Line 168,174: The capitialization of lchoice and tchoice does not match line 9.

You declare highScore() and bScience() as member functions, but you have not implemented these function.s However, you attempt to call these functions. This will result in linker errors.


Thanks to provide me with that code you gave.

Now I want to do something in the 'highScore' function. It should be like this:
It should use the concept of data file handling to store the user's name along with their scores and then compare the scores. When a user enters 'HS' or 'hs', it should display him the highest scores in order of highest to lowest.

Second, I want to see a fresh screen each time a new function is called or a new question is displayed which I can't see in your code.

Third, the questions and the answers are stored in text files (in Notepad), like when a user enters 'Beginner' as his level and 'Sciences' as his interest, the 'bScQues' (.txt) file should open up in which there are 10 questions on Science and display them one after the other (not all questions in one go). When the user enters 'a', 'b' ,c' or 'd' as one of his choice, the 'userAns' should match with 'ans' (real one). This should be done in 'quizComp' function. Data file handling should be applied in it to read the file.

Provide with any further help,
Thanks.
Second, I want to see a fresh screen each time a new function is called or a new question is displayed which I can't see in your code.


As my comment at line 5 indicates, clrscr() is not a standard function. i.e. It does not exist in a standard C++ compliant library. However, it does exist in Turbo C++, so you can just delete my lines 5 and 6 and use the Turbo C version. I inserted lines 5 and 6 so that I would not have to remove all your calls to clrscr().

An alternative is the following:
1
2
3
void clrscr ()
{  system ("cls");
}


However, the use of the system() call is generally considered poor practice.

As for further help, you are going to have to attempt the file handling yourself. I'm not going to write your assignment for you. If you have specific questions, post those questions and someone will try and help.

AbstractionAnon:

As my comment at line 5 indicates, clrscr() is not a standard function. i.e. It does not exist in a standard C++ compliant library. However, it does exist in Turbo C++, so you can just delete my lines 5 and 6 and use the Turbo C version. I inserted lines 5 and 6 so that I would not have to remove all your calls to clrscr().

An alternative is the following:

1
2
3
void clrscr ()
{  system ("cls");
}



However, the use of the system() call is generally considered poor practice.


Thanks, it worked but still I can't see the word 'IK' I made using '*' properly, it looks wavy everywhere. I want to make it look like a heading.

Can you please tell me how I can read questions from the text file 'bScQues'? I've learnt till now the use of 'ifstream' , 'ofstream' and 'fstream' to do both read and write.
Is this statement correct?:

1
2
3
ifstream f1;
f1.open("bScQues", ios::in);
cin>>userAns;


But I want one question at a time while reading. Should I use eof() ? If yes, then how?

Thanks.


Last edited on
Till now I've written the following code in bScience():

1
2
3
4
5
6
7
8
9
10
11
12
13
void bScience()
{ clrscr();
  char userAns, ch;
  cout<<"\n You're interested in 'Sciences'";
  cout<<"\n and you think you're a 'Beginner'";
  cout<<"\n So, let's start...";
  ifstream f1;
  f1.open("bScQues", ios::in);
  f1.get(ch);
  f1.close();
  cout<<"\n What should be the correct answer?:";
  cin>>userAns;
  }


When I execute it, after choosing the level and subject it goes back asking 'userName'. Why so?
Last edited on
Probably because you have a loop or a recursive call to Quiz::Start(), however, I don't see any loops or recursive calls in the code in the last code you posted.
The following is what I've written in bScQues():

1
2
3
4
5
6
7
8
9
10
11
12
13
14
void bScience()
{ clrscr();
  char userAns, ch[50];
  cout<<"\n You're interested in 'Sciences'";
  cout<<"\n and you think you're a 'Beginner'";
  cout<<"\n So, let's start...";
  ifstream f1;
  f1.open("bScQues");
  while(!f1.eof())
  {f1.getline(ch, 50, '');
  cout<<ch;}
  cout<<"\n What should be the correct answer?:";
  cin>>userAns;
  }


I'm getting the error :-
Character constant must be one or two characters long
Why so?
Line 10: Your delimiter has no character between the single quotes. That is not a valid character literal. Exactly what character do think getline would be looking for if that were legal?
AbstractionAnon :

Line 10: Your delimiter has no character between the single quotes. That is not a valid character literal. Exactly what character do think getline would be looking for if that were legal?


I did the following to open the file but nothing happens when I choose Science as my topic!:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void bScience()
{ clrscr();
  char userAns, ch[50];
  cout<<"\n You're interested in 'Sciences'";
  cout<<"\n and you think you're a 'Beginner'";
  cout<<"\n So, let's start...";
  ifstream f1;
  f1.open("bScQues.txt", ios::in);
  while(!f1.eof())
  {f1.getline(ch, 50, '.');
  cout<<ch;}
  f1.close();
  cout<<"\n What should be the correct answer?:";
  cin>>userAns;
  }


It just comes back asking : "How should we call you?:"
Pages: 123