Undefined symbol error in Turbo C++

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


I repeat my previos answer:
abstractionanon wrote:
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.


At line 19 in you full post, you've declared bScience as a member of your Quiz class, but line 1 of your last post shows bScience to be a global function, not a member of the Quiz class. However, this does not explain the problem you're seeing.

Since that message is not displayed by bScience(), your problem is elsewhere.

If you want futher help, you're going to need to post your current code in its entirety.

AbstractionAnon:

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

I repeat my previos answer:
abstractionanon wrote:
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.


At line 19 in you full post, you've declared bScience as a member of your Quiz class, but line 1 of your last post shows bScience to be a global function, not a member of the Quiz class. However, this does not explain the problem you're seeing.

Since that message is not displayed by bScience(), your problem is elsewhere.

If you want futher help, you're going to need to post your current code in its entirety.


Here's my complete 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
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
//The Infinite Knowledge Quiz Program
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<fstream.h>
#include<string.h>

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";
    cout<<"\n affairs, 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";
    cout<<"\n 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();
	}

    }
}

void bScience()
{ clrscr();
  char userAns, ch[30];
  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");
  cin.getline(ch, 30);
  cout<<ch;
  f1.close();
  cout<<"\n What should be the correct answer?:";
  cin>>userAns;
  }


What should I do now?
Line 71: You call q1.start().
Line 76: You call q1.start() again. When you return from the call at line71, you're going to fall through to the call at line 76. What do you think is going to happen the second time you call q1.start()?
AbstractionAnon:

Line 71: You call q1.start().
Line 76: You call q1.start() again. When you return from the call at line71, you're going to fall through to the call at line 76. What do you think is going to happen the second time you call q1.start()?


You mean to say that when the second time I call q1.start() it's due to this that my program is going back asking userName?

1. When I remove line 76, after asking the subject it comes back to the code.

2. When I remove line 76 and add the following in the bScience() function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
void bScience()
{ clrscr();
  char userAns, ch[30];
  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");
  while (!f1.eof())
  {f1.getline(ch, 30, '\n');
  cout<<ch;}
  cout<<"\n What should be the correct answer?:";
  cin>>userAns;
  }


it comes back to the code. Why it isn't executing?
You mean to say that when the second time I call q1.start() it's due to this that my program is going back asking userName?

Yes. If you call q1.Start() twice, you're going to ask for user name twice, because that is what q1.Start() does.

Why it isn't executing?

Where do you call bScience()? You have to call a function for it to execute.

BTW: If you add a call to bScience() the way you have it, you're going to get linker errors. As I pointed out before, you have bScience() as a global function. Whereas your function declaration says it's a member of Quiz. For the second time, change line 214 to void Quiz::bScience().



AbstractionAnon:

You mean to say that when the second time I call q1.start() it's due to this that my program is going back asking userName?

Yes. If you call q1.Start() twice, you're going to ask for user name twice, because that is what q1.Start() does.

Why it isn't executing?

Where do you call bScience()? You have to call a function for it to execute.

BTW: If you add a call to bScience() the way you have it, you're going to get linker errors. As I pointed out before, you have bScience() as a global function. Whereas your function declaration says it's a member of Quiz. For the second time, change line 214 to void Quiz::bScience().


I've changed the code by calling the function as:

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
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);
    }

}

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";
    cout<<"\n affairs, 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";
    cout<<"\n 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'))
    clrscr();
	{   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;
	   if((tchoice=='S')||(tchoice=='s'))
	    { clrscr();
	    bScience();}
	}

    }
}

void Quiz::bScience()
{ clrscr();
  char userAns, ch[50];
  cout<<"\n\n\n\n You're interested in 'Sciences'";
  cout<<"\n and you think you're a 'Beginner'";
  cout<<"\n So, let's start...";
  clrscr();
  ifstream f1;
  f1.open("bScQues.txt");
  while (!f1.eof())
  {f1.getline(ch, 50, '\n');
  cout<<ch;}
  cout<<"\n\n What's your answer?:";
  cin>>userAns;
  }


It's doing the job perfectly. One thing is still not cleared, I've the following text in the .txt file:

What's your scientific name?

a> Homosoyans
b> Homosapiens
c> Humane
d> Sapiens


But when the file opens and shows the content, it's like this:

What's your scientific name?a> Homosoyans ...large gap... b>Homosapiensc>Humane
d> Sapiens


I want to look it as it's in the file...How?
What's your answer?:[/tt]
Last edited on
Line 184: You don't output an endl or \n. endl is preferred in C++.

Last edited on
AbstractionAnon :

Line 184: You don't output an endl or \n. endl is preferred in C++.


Thanks, it worked!

Now, I want to compare the actual answer to the userAns using Data File Handling.
For example, the answer to the first question is 'b', how can I compare it with the answer provided in the file 'bScAns.txt'? Or should I go to some other method?

Why aren't the lines 176, 177 and 178 compiling?
And, how to display one question at a time present in 'bScQues.txt' file if there are 10 in total. As I've said before, one question, then answer compare then again second question, then compare...Will a loop help?
Last edited on
What do you mean lines 176-178 are not compiling? I see nothing wrong with them. If you're getting compile errors on them, please post the exact errors messages from the compiler.

What I do see is that lines 176-178 are immediately followed by a call to clrscr().
What is happening is that the lines are displaying, but you immediately erase them so you never see them. I suggest you spend a few minutes actually reading your code.

As for reading from the file and comparing answers, you going to have to do that yourself. I'm not going to write the code for you. If you get stuck, post what you have.



AbstractionAnon:

What do you mean lines 176-178 are not compiling? I see nothing wrong with them. If you're getting compile errors on them, please post the exact errors messages from the compiler.

What I do see is that lines 176-178 are immediately followed by a call to clrscr().
What is happening is that the lines are displaying, but you immediately erase them so you never see them. I suggest you spend a few minutes actually reading your code.


Even when I remove clrscr() in line 174, I can't see the three line 176-178 before the file is opened.

And how to display one question at a time present in 'bScQues.txt' file if there are 10 in total? Should I use a for or while loop?
Last edited on
Removing the clrscr() at 174 is not the problem. The issue is the clrscr() at 179.
READ THE CODE. You display the three lines, then clear the screen.
How do you expect to see what you just displayed?

Should I use a for or while loop?

Either will work.

AbstractionAnon:

Removing the clrscr() at 174 is not the problem. The issue is the clrscr() at 179.
READ THE CODE. You display the three lines, then clear the screen.
How do you expect to see what you just displayed?


Removing the clrscr(); at 179 worked!

When I'll finish the question display code, I'll post it here.
Last edited on
@AbstractionAnon, is the following code correct?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void Quiz::bScience()
{ clrscr();
  char userAns, ch[50], ans;
  ifstream f2;
  f2.open("bScAns.txt");
  cout<<"\n\n\n\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");
  {cin.getline(ch, 50, '\n');
  cout<<ch<<endl;}
  f1.close();
  cout<<"\n\n What's your answer?:";
  cin>>userAns;
  char c;
  ans.get(c);
  if(ch==c)
  { cout<<"\n\n Correct!";
  }
  else
  { cout<<"\n Sorry, but that's a wrong answer!";}
  }


But while executing I'm receiving the following errors:
1. Structure required on left side of . or * in ans.get(c)
2. Can't convert char to char* in if(ch==c)

How to solve this? The only answer in bScAns.txt file is a
Line 11: You're trying to read the question from cin (standard input), not the stream you opened on line 10.

Line 17: What is it you're trying to do here? ans is a simple char. It does not have a get method. Are you trying to get a char from your f2 stream?

Line 18: You're trying to compare an array (ch) to a simple char (c). That won't work. ch contains your question. Why are you comparing anything to your question? This is a good example you why you should use meaningful variable names. ch doesn't indicate anything meaningful. If you had used a variable name such as quest to hold your question, it would have been obvious that this line didn't make sense.
AbstractionAnon :

Line 11: You're trying to read the question from cin (standard input), not the stream you opened on line 10.


When I change cin to f1 it results the same error.

Line 17: What is it you're trying to do here? ans is a simple char. It does not have a get method. Are you trying to get a char from your f2 stream?


By what should I replace this to?
By what should I replace this to?

As I stated earlier, I'm not going to write the code for you. You need to learn how to write the code yourself.

But while executing I'm receiving the following errors:

Those are compile time errors, not execution errors.


@AbstractionAnon:

Is this code correct?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
void Quiz::bScience()
{ clrscr();
  char userAns, ch[50];
  cout<<"\n\n\n\n You're interested in 'Sciences'";
  cout<<"\n and you think you're a 'Beginner'";
  cout<<"\n So, let's start...";
  clrscr();
  for( int i=0;i<10;i++)
  {
  ifstream f1;
  f1.open("bScQues.txt");
  while (!f1.eof())
  {f1.getline(ch, 50, '\n');
  cout<<ch<<endl;}
  cout<<"\n\n What's your answer?:";
  cin>>userAns;
  ifstream f2;
  f2.open("bScAns.txt");
  while (!f2.eof())
  {f2.getline(ch, 50, '\n');
  cout<<ch<<endl;}
  void quizComp();}
  }


While executing, the question repeats 10 times mainly because of for( int i=0;i<10;i++). I included this because I want the 10 questions to be printed seperately. I know it's wrong, but I can't figure out the exact code for this. Could you please give me a hint?

Thanks.
You're currently opening each file 10 times. Each time you do so, you're positioned at the beginning of file.

Move lines 10-11 and 17-18 to in front of line 8.

What is line 22? That is a function declaration, not a function call.
AbstractionAnon:

Move lines 10-11 and 17-18 to in front of line 8.


Done. moved. But while I write the following lines I get an error- identifier bScience cannot have a type qualifier..in front of line 2 in above code. Why so? (After line 167 in KVaibhav01 (17))

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
if((tchoice=='A')||(tchoice=='a'))
	   { clrscr();
	    bArts();}
	   if((tchoice=='E')||(tchoice=='e'))
	   { clrscr();
	    bEnt();}
	   if((tchoice=='G')||(tchoice=='g'))
	   { clrscr();
	     bGeo();}
	   if((tchoice=='I')||(tchoice=='i'))
	   { clrscr();
	     bInd();}
	   if((tchoice=='L')||(tchoice=='l'))
	   { clrscr();
	     bLang();}
	   if((tchoice=='S')||(tchoice=='s'))
	   { clrscr();
	     bSports();}
	   else
	   { cout<<"\n Wrong selection. Enter again:";
	     cin>>tchoice;}

	}
    if((lchoice=='I')||(lchoice=='i'))
  { clrscr();
    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;
     if((tchoice=='S')||(tchoice=='s'))
	    { clrscr();
	    iScience();}
	   if((tchoice=='A')||(tchoice=='a'))
	   { clrscr();
	    iArts();}
	   if((tchoice=='E')||(tchoice=='e'))
	   { clrscr();
	    iEnt();}
	   if((tchoice=='G')||(tchoice=='g'))
	   { clrscr();
	     iGeo();}
	   if((tchoice=='I')||(tchoice=='i'))
	   { clrscr();
	     iInd();}
	   if((tchoice=='L')||(tchoice=='l'))
	   { clrscr();
	     iLang();}
	   if((tchoice=='S')||(tchoice=='s'))
	   { clrscr();
	     iSports();}
	   else
	   { cout<<"\n Wrong selection. Enter again:";
	     cin>>tchoice;}

    if((tchoice=='E')||(lchoice=='e'))
     {  
clrscr();
    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;
     if((tchoice=='S')||(tchoice=='s'))
	    { clrscr();
	    eScience();}
	   if((tchoice=='A')||(tchoice=='a'))
	   { clrscr();
	    eArts();}
	   if((tchoice=='E')||(tchoice=='e'))
	   { clrscr();
	    eEnt();}
	   if((tchoice=='G')||(tchoice=='g'))
	   { clrscr();
	     eGeo();}
	   if((tchoice=='I')||(tchoice=='i'))
	   { clrscr();
	     eInd();}
	   if((tchoice=='L')||(tchoice=='l'))
	   { clrscr();
	     eLang();}
	   if((tchoice=='S')||(tchoice=='s'))
	   { clrscr();
	     eSports();}
	   else
	   { cout<<"\n Wrong selection. Enter again:";
	     cin>>tchoice;}


What is line 22? That is a function declaration, not a function call.


I've changed it to quizComp() only.
Last edited on
while I write the following lines I get an error- identifier bScience cannot have a type qualifier..in front of line 2 in above code.

Don't have enough context to evaluate that statement.

Lines 30,48. If the user enters S, you will execute both iScience() and iSports(). I pointed this out to you once before.

Lines 62-80. Ditto.


Pages: 123