Final Assignment problems.

This is my final assignment for my only programming class, so of course it would be very long lol. It has several issues that do not come up when the programs run on their own. I will include the compiler messages.










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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
  #include<iostream>
#include<iomanip>
#include<string>
#include<fstream>
#include<cstdlib>
#include<windows.h>


using namespace std;

void menu();
void tutor();
void processing();
void getRscore(char[]);
void getBscore(char[]);
void ivnmain();

void ClearScreen()
  {
  HANDLE                     hStdOut;
  CONSOLE_SCREEN_BUFFER_INFO csbi;
  DWORD                      count;
  DWORD                      cellCount;
  COORD                      homeCoords = { 0, 0 };

  hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
  if (hStdOut == INVALID_HANDLE_VALUE) return;

  
  if (!GetConsoleScreenBufferInfo( hStdOut, &csbi )) return;
  cellCount = csbi.dwSize.X *csbi.dwSize.Y;


  if (!FillConsoleOutputCharacter(
    hStdOut,
    (TCHAR) ' ',
    cellCount,
    homeCoords,
    &count
    )) return;

 
  if (!FillConsoleOutputAttribute(
    hStdOut,
    csbi.wAttributes,
    cellCount,
    homeCoords,
    &count
    )) return;

 
  SetConsoleCursorPosition( hStdOut, homeCoords );
  }







char EXIT='N'; 


int main()

{

menu();


return 0;

}


void menu ()
{
 char choice;
 
 ClearScreen();
 
 
 
 cout<<"Welcome to the menu which contains a few of the programs I have created \n";
 cout<<"during my class time. Please enter your menu choice after the menu is displayed.\n";
 cout<<"Please only enter the upper or lower case letters presented as menu options,\n";
 cout<<"numbers will not be accepted.\n\n";
 cin>>choice;
 while  (choice!='a' && choice!='A' && choice!='b' && choice!='B' && choice!='c' && choice!='C' && choice!='d' && choice!='D' && choice!='e' && choice!='E')
    {
    cout<<"That is not a valid entry, please enter a letter that was presented as\n";
    cout<<"a menu option, case does not matter." ;
    cin>>choice;
    cout<<endl <<endl;
          
}



	do
	{
	switch(choice)
	{
		case 'a': 
			 'A': tutor();
			 	 break;
		case 'b':
			 'B': processing();
			 	 break;
		case 'c':
			 'C': grademachine();
			 	 break;
		case 'd':
			 'D': ivnmain();
			 	 break;
		case 'e':
			 'E': Exit();
	}            break;

}
    while (EXIT=='N' || EXIT=='n')


   cout<<"Good bye";
   
   system ("pause");


}




void tutor()
{ 
     
    ClearScreen(); 
     
     cout<<"Welcome to the Math Tutor program, run it as many times \n";
    cout<<"as you need for practice!" <<endl <<endl;
    
    unsigned seed= time (0);
    srand (seed);
    
    cout<<"You will now be presented with a math problem, please solve it.\n";
    
    system ("pause");
    cout<< endl;
    double num1, num2, answer, studentanswer;
    
    num1= rand() % 100;
    num2= rand() % 100;
    answer=num2-num1;
    
    
    cout<<"(" << num1 <<" + y = " << num2 <<")" << endl;
    cout<<"Please enter what you believe to be the correct answer: ";
    cin>> studentanswer;  
    cout<<endl <<endl;
    
    if (answer==studentanswer)
       cout<<"You are correct!!!" <<endl;
       
       else
       cout<<"Your answer is not correct. The correct answer is: " <<answer <<endl;
}

const int SIZE=20;
void processing()

{
     
   ClearScreen();  
     
     int numofnum, sumofnum, number;
double averagenum;

numofnum=0, sumofnum=0, averagenum=0;

 ifstream numfile;
 
 numfile.open("random.txt");
 
 if (numfile)
 
    {
    while (numfile >> number)
          {
                   
                   numofnum++;
                   sumofnum+=number;
                   
                   }
                   
          averagenum=sumofnum/numofnum;
          
          cout<<"The number of numbers in the file is: " <<numofnum <<", the sum of all the numbers is: " <<sumofnum <<",\n";
          cout<<"while the average of the numbers is: " <<averagenum <<"." <<endl;
          
            system ("pause");
            
            
            }
            
            else 
            {
            cout<<"There was an error reading the file, goodbye." <<endl;
            }
            
            
}

void grademachine()
{
     ClearScreen();
     
    char studentanswers[SIZE];
	char correctanswers[SIZE];
	char wrong[SIZE];
	int qnumber[SIZE];
    int numberWrong = 0;
    int f=0;
    int average=0;
	getRscore(studentanswers);

	getBscore(correctanswers);

	for (int index = 0; index < SIZE; index++)
	{
		if (studentanswers[index] != correctanswers[index])
		{
			wrong[numberWrong] = studentanswers[index];
			numberWrong++;
		    qnumber[f]=index;
		    f++;
        
        
        }
		
		
		
	}
	
	cout<<"The student answers have been pulled from their file and compared to \n";
	cout<<"the correct answers. The amount of answers that were wrong is: " <<numberWrong<<endl;
	cout<<"The incorrect answers are as follows: ";
	
	for(int i = 0; i < numberWrong; i++)
	{
		cout<<qnumber[i]+1 <<"." << wrong[i] << "   ";
	}
    int numright=SIZE-numberWrong;
    
    average=numright/SIZE;
    
    cout<<setprecision(2) <<fixed;
    cout<<"The average is: " <<average;
	cout << endl;
}

void getRscore(char score[])
{	ifstream inFile;
	int count = 0;

	inFile.open("StudentsAnswers.txt");
	if (inFile.fail())
	{
		cout << "File failed to open " << endl;
		cin.ignore();
		exit(0);
	}

	inFile >> score[count];
	
	while(inFile)
	{
		count++;
		inFile >> score[count];	
	}

	inFile.close();
}

void getBscore(char score[])

{ifstream inFile;
	int count = 0;

	inFile.open("CorrectAnswers.txt");
	
	if (inFile.fail())
	{
		cout << "File failed to open " << endl;
		cin.ignore();
		exit(0);
	}

	inFile >> score[count];

	while(inFile)
	{
		count++;
		inFile >> score[count];
	}

	inFile.close();
}





class Inventory
{
	private:
		int itemNumber;
		int quantity;
		double cost;
		double totalcost;
	public:
		Inventory();
		Inventory(int, int, double);
		void setItemnumber(int);
		void setQuantity(int);
		void setCost(double);
		void setTotalCost(int, double);
		int getItemNumber() const;
		int getQuantity() const;
		double getCost() const;
		double getTotalCost() const;
};

Inventory::Inventory()
{
	itemNumber=0;
	quantity=0;
	cost=0;
	totalcost=0;
}

Inventory::Inventory(int number, int amount, double Cost)
{
	
	
	
	itemNumber=number;
	quantity=amount;
	cost=Cost;
	setTotalCost(quantity, cost);	
}

void Inventory::setItemnumber(int number)
{
	itemNumber=number;
}

void Inventory::setQuantity(int amount)
{
	quantity=amount;
}

void Inventory::setCost(double Cost)
{
	cost=Cost;
}

void Inventory::setTotalCost(int amount, double Cost)
{
	totalcost=amount*Cost;
}

int Inventory::getItemNumber() const
{
	return itemNumber;
}

int Inventory::getQuantity() const
{
	return quantity;
}

double Inventory::getCost() const
{
	return cost;
}

double Inventory::getTotalCost() const
{
	return totalcost;
}

void ivnmain()




{
     ClearScreen();


int ITEMNUMBER, QUANTITY;
double COST;

cout<<"Welcome, when asked to enter informations please do not enter" <<endl;
cout<<"a negative number. Please enter the first items number: ";
cin>>ITEMNUMBER;
cout<<"Please enter the first items quantity: ";
cin>>QUANTITY;
cout<<"Please enter the first items cost: ";
cin>>COST;

Inventory item1;
item1.setItemnumber(ITEMNUMBER);
item1.setQuantity(QUANTITY);
item1.setCost(COST);
item1.setTotalCost(QUANTITY, COST);

cout<<"Thankyou, now for the second item: " <<endl;
cout<<"Please enter the second items number:";
cin>>ITEMNUMBER;
cout<<"Please enter the second items quantity: ";
cin>>QUANTITY;
cout<<"Please enter the second items cost: ";
cin>>COST;

Inventory item2(ITEMNUMBER, QUANTITY, COST);

cout<< setprecision(2) <<fixed <<endl <<endl;

cout<<"Here are the two items you have put into inventory:" <<endl;
cout<<"Item numbered " <<item1.getItemNumber() <<" has " <<item1.getQuantity();
cout<<" in stock at a price" <<endl;
cout<<"of $" <<item1.getCost() <<". In total they are worth $" <<item1.getTotalCost();
cout<<"." <<endl <<endl;



cout<<"Item numbered " <<item2.getItemNumber() <<" has " <<item2.getQuantity();
cout<<" in stock at a price" <<endl;
cout<<"of $" <<item2.getCost() <<". In total they are worth $" <<item2.getTotalCost() <<endl;

system ("pause");



}


 void Exit()
 {
     
     ClearScreen();
     
     
      cout<<"Are you sure you want to exit? Y/N ";
      
      cin>>EXIT;
}
Compiler: Default compiler
Executing g++.exe...
g++.exe "E:\exam.cpp" -o "E:\exam.exe" -g3 -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib" -g3
E:\exam.cpp: In function `void menu()':
E:\exam.cpp:105: error: expected `;' before ':' token

E:\exam.cpp:108: error: expected `;' before ':' token
E:\exam.cpp:111: error: expected `;' before ':' token
E:\exam.cpp:114: error: expected `;' before ':' token
E:\exam.cpp:117: error: expected `;' before ':' token
E:\exam.cpp:124: error: expected `;' before "cout"

E:\exam.cpp: At global scope:
E:\exam.cpp:168: error: `const int SIZE' redeclared as different kind of symbol

C:/Dev-Cpp/include/windef.h:322: error: previous declaration of `typedef struct tagSIZE SIZE'
E:\exam.cpp:168: error: declaration of `const int SIZE'
C:/Dev-Cpp/include/windef.h:322: error: conflicts with previous declaration `typedef struct tagSIZE SIZE'

E:\exam.cpp: In function `void grademachine()':
E:\exam.cpp:224: error: `studentanswers' undeclared (first use this function)

E:\exam.cpp:224: error: (Each undeclared identifier is reported only once for each function it appears in.)
E:\exam.cpp:226: error: `correctanswers' undeclared (first use this function)
E:\exam.cpp:228: error: expected primary-expression before ';' token
E:\exam.cpp:232: error: `wrong' undeclared (first use this function)
E:\exam.cpp:234: error: `qnumber' undeclared (first use this function)

E:\exam.cpp:252: error: expected primary-expression before '-' token
E:\exam.cpp:254: error: expected primary-expression before ';' token

Execution terminated
E:\exam.cpp: In function `void menu()':
E:\exam.cpp:105: error: expected `;' before ':' token

E:\exam.cpp:108: error: expected `;' before ':' token
E:\exam.cpp:111: error: expected `;' before ':' token
E:\exam.cpp:114: error: expected `;' before ':' token
E:\exam.cpp:117: error: expected `;' before ':' token

In a switch, multiple labels like
1
2
3
4
5
6
switch(choice)
{
    case 'a': 
        'A': /* ... */
        break;
}
are not permitted.
Instead you could use fall-through labels:
1
2
3
4
5
6
7
8
9
10
switch(choice)
{
    case 'a':
    case 'A': /* ... */
        break;
    case 'b':
    case 'B': /* ... */
        break;
    /* ... */
}


E:\exam.cpp:124: error: expected `;' before "cout"

In a do-while you have to put a ";" after the "while".

E:\exam.cpp: At global scope:
E:\exam.cpp:168: error: `const int SIZE' redeclared as different kind of symbol

C:/Dev-Cpp/include/windef.h:322: error: previous declaration of `typedef struct tagSIZE SIZE'
E:\exam.cpp:168: error: declaration of `const int SIZE'
C:/Dev-Cpp/include/windef.h:322: error: conflicts with previous declaration `typedef struct tagSIZE SIZE'

"SIZE" is already defined as something else in one of the headers, change its name.

E:\exam.cpp: In function `void grademachine()':
E:\exam.cpp:224: error: `studentanswers' undeclared (first use this function)

E:\exam.cpp:224: error: (Each undeclared identifier is reported only once for each function it appears in.)
E:\exam.cpp:226: error: `correctanswers' undeclared (first use this function)
E:\exam.cpp:228: error: expected primary-expression before ';' token
E:\exam.cpp:232: error: `wrong' undeclared (first use this function)
E:\exam.cpp:234: error: `qnumber' undeclared (first use this function)

E:\exam.cpp:252: error: expected primary-expression before '-' token
E:\exam.cpp:254: error: expected primary-expression before ';' token

Comes from the problem with "SIZE"
Well, for the first group of errors (from line 105 on to 124) you're using switch incorrectly. What you can do is use the function tolower(choice) and then simply check against the lowercase letter, making it function correctly. Hell, in any instance where you're checking against the capital and lowercase versions of a letter, throw in a tolower(variable) to make it simpler on the code (tolower can be found in the library ctype).

As for all of your issues with using SIZE... well, SIZE is already a structure in the windows.h header. Therefore, you cannot also declare it as a constant. So... pick a different name for SIZE, and all the issues relating to that (the rest of your errors in your program, actually) will be resolved.

I hope that helps.

EDIT: Well, it would appear that someone beat me to the punch... at least you have two confirmations on what is going wrong in your program.
Last edited on
The program now runs, but there are some bugs. Firstly, it will not reiterate the loop of the main function, which I intended to use to reopen the menu after the user was done with the program that they had chosen. Secondly, I have added some code which is supposed to ask the user if they want to use the program they chose again or return to the menu. It exits the main program completely instead. I only added that code to the "math tutor" function.
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
  #include<iostream>
#include<iomanip>
#include<string>
#include<fstream>
#include<cstdlib>
#include<windows.h>


using namespace std;

void menu();
void tutor();
void processing();
void getRscore(char[]);
void getBscore(char[]);
void ivnmain();
void grademachine();
void Exit();
void ClearScreen()

  {
  HANDLE                     hStdOut;
  CONSOLE_SCREEN_BUFFER_INFO csbi;
  DWORD                      count;
  DWORD                      cellCount;
  COORD                      homeCoords = { 0, 0 };

  hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
  if (hStdOut == INVALID_HANDLE_VALUE) return;

  
  if (!GetConsoleScreenBufferInfo( hStdOut, &csbi )) return;
  cellCount = csbi.dwSize.X *csbi.dwSize.Y;


  if (!FillConsoleOutputCharacter(
    hStdOut,
    (TCHAR) ' ',
    cellCount,
    homeCoords,
    &count
    )) return;

 
  if (!FillConsoleOutputAttribute(
    hStdOut,
    csbi.wAttributes,
    cellCount,
    homeCoords,
    &count
    )) return;

 
  SetConsoleCursorPosition( hStdOut, homeCoords );
  }







char EXIT='N'; 


int main()

{

menu();


return 0;

}


void menu ()
{
 char choice;
 
 ClearScreen();
 
 do
 {
 
 cout<<"Welcome to the menu which contains a few of the programs I have created \n";
 cout<<"during my class time. Please enter your menu choice after the menu is displayed.\n";
 cout<<"Please only enter the upper or lower case letters presented as menu options,\n";
 cout<<"numbers will not be accepted.\n\n";
 cout<<"The choices are: " <<endl <<endl;
 cout<<"\t A: Math Tutor Exercise\n";
 cout<<"\t B: Number Processing\n";
 cout<<"\t C: Grade Machine\n";
 cout<<"\t D: Inventory Class\n";
 cout<<"\t E: Press E to Exit the program\n" <<endl;
 
 
 
 
 cin>>choice;
 

 while  (choice!='a' && choice!='A' && choice!='b' && choice!='B' && choice!='c' && choice!='C' && choice!='d' && choice!='D' && choice!='e' && choice!='E')
    {
    cout<<"That is not a valid entry, please enter a letter that was presented as\n";
    cout<<"a menu option, case does not matter." ;
    cin>>choice;
    cout<<endl <<endl;
          
}



	
	
	switch(choice)
	{
		case 'a': 
		case 'A': tutor();
			 	 break;
		case 'b':
		case 'B': processing();
			 	 break;
		case 'c':
		case 'C': grademachine();
			 	 break;
		case 'd':
		case 'D': ivnmain();
			 	 break;
		case 'e':
		case 'E': Exit();
	}            break;

}
    while (EXIT=='N' || EXIT=='n');


   cout<<"Good bye";
   
   system ("pause");


}




void tutor()
{ 
   char ongoing='n';
   
   do
   {
     
    ClearScreen(); 
     
     cout<<"Welcome to the Math Tutor program, run it as many times \n";
    cout<<"as you need for practice!" <<endl <<endl;
    
    unsigned seed= time (0);
    srand (seed);
    
    cout<<"You will now be presented with a math problem, please solve it.\n";
    
    system ("pause");
    cout<< endl;
    double num1, num2, answer, studentanswer;
    
    num1= rand() % 100;
    num2= rand() % 100;
    answer=num2-num1;
    
    
    cout<<"(" << num1 <<" + y = " << num2 <<")" << endl;
    cout<<"Please enter what you believe to be the correct answer: ";
    cin>> studentanswer;  
    cout<<endl <<endl;
    
    if (answer==studentanswer)
       cout<<"You are correct!!!" <<endl;
       
       else
       cout<<"Your answer is not correct. The correct answer is: " <<answer <<endl;


 cout<<"Would you like to use the math tutor again? Please enter Y or N" <<endl;

}



  while (ongoing=='Y' || ongoing=='y');
}
void processing()

{
     
   ClearScreen();  
     
     int numofnum, sumofnum, number;
double averagenum;

numofnum=0, sumofnum=0, averagenum=0;

 ifstream numfile;
 
 numfile.open("random.txt");
 
 if (numfile)
 
    {
    while (numfile >> number)
          {
                   
                   numofnum++;
                   sumofnum+=number;
                   
                   }
                   
          averagenum=sumofnum/numofnum;
          
          cout<<"The number of numbers in the file is: " <<numofnum <<", the sum of all the numbers is: " <<sumofnum <<",\n";
          cout<<"while the average of the numbers is: " <<averagenum <<"." <<endl;
          
            system ("pause");
            
            
            }
            
            else 
            {
            cout<<"There was an error reading the file, goodbye." <<endl;
            }
            
            
}

void grademachine()
{
     ClearScreen();
     
    char studentanswers[20];
	char correctanswers[20];
	char wrong[20];
	int qnumber[20];
    int numberWrong = 0;
    int f=0;
    double average=0;
	getRscore(studentanswers);

	getBscore(correctanswers);

	for (int index = 0; index < 20; index++)
	{
		if (studentanswers[index] != correctanswers[index])
		{
			wrong[numberWrong] = studentanswers[index];
			numberWrong++;
		    qnumber[f]=index;
		    f++;
        
        
        }
		
		
		
	}
	
	cout<<"The student answers have been pulled from their file and compared to \n";
	cout<<"the correct answers. The amount of answers that were wrong is: " <<numberWrong<<endl;
	cout<<"The incorrect answers are as follows: ";
	
	for(int i = 0; i < numberWrong; i++)
	{
		cout<<qnumber[i]+1 <<"." << wrong[i] << "   ";
	}
    int numright=20-numberWrong;
    
    average=(numright/20.00)*100.00
    ;
    
    cout<<setprecision(2) <<fixed;
    cout<<"The average is: " <<average;
	cout << endl;
}


  
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
void getRscore(char score[])
{	ifstream inFile;
	int count = 0;

	inFile.open("StudentsAnswers.txt");
	if (inFile.fail())
	{
		cout << "File failed to open " << endl;
		cin.ignore();
		exit(0);
	}

	inFile >> score[count];
	
	while(inFile)
	{
		count++;
		inFile >> score[count];	
	}

	inFile.close();
}

void getBscore(char score[])

{ifstream inFile;
	int count = 0;

	inFile.open("CorrectAnswers.txt");
	
	if (inFile.fail())
	{
		cout << "File failed to open " << endl;
		cin.ignore();
		exit(0);
	}

	inFile >> score[count];

	while(inFile)
	{
		count++;
		inFile >> score[count];
	}

	inFile.close();
}





class Inventory
{
	private:
		int itemNumber;
		int quantity;
		double cost;
		double totalcost;
	public:
		Inventory();
		Inventory(int, int, double);
		void setItemnumber(int);
		void setQuantity(int);
		void setCost(double);
		void setTotalCost(int, double);
		int getItemNumber() const;
		int getQuantity() const;
		double getCost() const;
		double getTotalCost() const;
};

Inventory::Inventory()
{
	itemNumber=0;
	quantity=0;
	cost=0;
	totalcost=0;
}

Inventory::Inventory(int number, int amount, double Cost)
{
	
	
	
	itemNumber=number;
	quantity=amount;
	cost=Cost;
	setTotalCost(quantity, cost);	
}

void Inventory::setItemnumber(int number)
{
	itemNumber=number;
}

void Inventory::setQuantity(int amount)
{
	quantity=amount;
}

void Inventory::setCost(double Cost)
{
	cost=Cost;
}

void Inventory::setTotalCost(int amount, double Cost)
{
	totalcost=amount*Cost;
}

int Inventory::getItemNumber() const
{
	return itemNumber;
}

int Inventory::getQuantity() const
{
	return quantity;
}

double Inventory::getCost() const
{
	return cost;
}

double Inventory::getTotalCost() const
{
	return totalcost;
}

void ivnmain()




{
     ClearScreen();


int ITEMNUMBER, QUANTITY;
double COST;

cout<<"Welcome, when asked to enter informations please do not enter" <<endl;
cout<<"a negative number. Please enter the first items number: ";
cin>>ITEMNUMBER;
cout<<"Please enter the first items quantity: ";
cin>>QUANTITY;
cout<<"Please enter the first items cost: ";
cin>>COST;

Inventory item1;
item1.setItemnumber(ITEMNUMBER);
item1.setQuantity(QUANTITY);
item1.setCost(COST);
item1.setTotalCost(QUANTITY, COST);

cout<<"Thankyou, now for the second item: " <<endl;
cout<<"Please enter the second items number:";
cin>>ITEMNUMBER;
cout<<"Please enter the second items quantity: ";
cin>>QUANTITY;
cout<<"Please enter the second items cost: ";
cin>>COST;

Inventory item2(ITEMNUMBER, QUANTITY, COST);

cout<< setprecision(2) <<fixed <<endl <<endl;

cout<<"Here are the two items you have put into inventory:" <<endl;
cout<<"Item numbered " <<item1.getItemNumber() <<" has " <<item1.getQuantity();
cout<<" in stock at a price" <<endl;
cout<<"of $" <<item1.getCost() <<". In total they are worth $" <<item1.getTotalCost();
cout<<"." <<endl <<endl;



cout<<"Item numbered " <<item2.getItemNumber() <<" has " <<item2.getQuantity();
cout<<" in stock at a price" <<endl;
cout<<"of $" <<item2.getCost() <<". In total they are worth $" <<item2.getTotalCost() <<endl;

system ("pause");



}


 void Exit()
 {
     
     ClearScreen();
     
     
      cout<<"Are you sure you want to exit? Y/N ";
      
      cin>>EXIT;

    

}























 
I had to submit it in two posts because it's so long. Sorry about that.
I still need help with this. I cannot figure out why it will not run correctly.
line 133, you've put the "break" instruction after the closing accolade "}", therefore it's the do-while loop thats "broken".

In your tutor() function you forgot to read the value of "ongoing" at the end of the loop.
Thank you.
Topic archived. No new replies allowed.