Text Counting Program, No Errors, Doesn't Work

I'm using Visual Studio. No Errors are declared, but this will not display any of my menu. I think it is because the while(inputfile) meant to measure the integer values and count them is in some kind of loop.

What do!?

Regards,
John
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
  /*
<John P>
CS M10A
Topic D Project First Program
TopicD.cpp
Status: Working
*/


#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

int main()
{
	// Variable Declarations 
	int integer,	// integer in file
		lrg_int = -32767,	// the largest integer
		sml_int = 32767,	// the smallest integer
		sum_int = 0,	// sum of integers
		num_int = 0,	// number of integers
		avg_int;	// average of integers


	// Read Text File
	ifstream inputFile;
	inputFile.open("random.txt");

	// Display error if file doesn't exist
	if (!inputFile)
	{
		cout << "Cannot open the file random.txt /n";
			return 0; // Closes program after attempt to open file fails.
	}

	// Read the integers from inputfile random.txt
	inputFile >> integer; 

	while (inputFile)
	{
		num_int++;						// Increments number of integers in file
		sum_int = sum_int + integer;	// Determines running total of integers in file
		if (integer > lrg_int)			// Replaces lrg_int with the largest running integer
			lrg_int = integer;
		if (integer < sml_int)			// Replaces sml_int with the smallest running integer
			sml_int = integer;
	}

	// Menu Creation
	char choice;

	do
	{
		// Display Menu
		cout << "Make a selection from the list \n"
			<< "A. Get the largest value \n"
			<< "B. Get the smallest value \n"
			<< "C. Get the sum of the values \n"
			<< "D. Get the average \n"
			<< "E. Get the number of values entered \n"
			<< "F. End this program \n \n \n";
		cin >> choice;

		// Validate Menu Selection
		while (!(choice >= 'A' && choice <= 'F' || choice >= 'a' && choice <= 'f'))
		{
			cout << "Please enter a valid menu choice: ";
			cin >> choice;
		}

		// Process User's Choice
		switch (choice)
		{
			case 'A' :
			case 'a' :	cout << "The largest value is " << lrg_int << endl;
						break;
			case 'B' :
			case 'b' :	cout << "The smallest value is " << sml_int << endl;
						break;
			case 'C' :
			case 'c' :	cout << "The sum of the values is " << sum_int << endl;
						break;
			case 'D' :
			case 'd' :	avg_int = sum_int / num_int;
						cout << "The average of the values is " << avg_int << endl;
						break;
			case 'E' :
			case 'e':	cout << "The number of values is " << num_int << endl;
						break;
		}
	} while (choice != 'F' || choice != 'f');

	// First requests then registers enter key in order to end program.
	cout << "Program Over \n \n \n \n";

	cout << "Press Enter to end --> \n \n \n";
	cin.get();		// Pressing the enter key here ends the program

	return 0;
}
Last edited on
I do not know how to attach text files on this forum. I keep the text file in the inner folder of visual studio with my program. It is entitled random.txt. Here is its contents:

42
468
335
501
170
725
479
359
963
465
706
146
282
828
962
492
996
943
828
437
392
605
903
154
293
383
422
717
719
896
448
727
772
539
870
913
668
300
36
895
704
812
323
334
674
665
142
712
254
869
548
645
663
758
38
860
724
742
530
779
317
36
191
843
289
107
41
943
265
649
447
806
891
730
371
351
7
102
394
549
630
624
85
955
757
841
967
377
932
309
945
440
627
324
538
539
119
83
930
542
834
116
640
659
705
931
978
307
674
387
22
746
925
73
271
830
778
574
98
513
987
291
162
637
356
768
656
575
32
53
351
151
942
725
967
431
108
192
8
338
458
288
754
384
946
910
210
759
222
589
423
947
507
31
414
169
901
592
763
656
411
360
625
538
549
484
596
42
603
351
292
837
375
21
597
22
349
200
669
485
282
735
54
1000
419
939
901
789
128
468
729
894
649
484
808
422
311
618
814
515
Topic archived. No new replies allowed.