Repeating a Menu

Im very new at programming and cant seem to figure out what these errors mean. Ive read that it means im not linking something correctly or using right library, but its not telling me which part is wrong.
Error 2 error LNK1120: 1 unresolved externals
Error 1 error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup


new problem: The program will only do the
1
2
if (choice == 'A' || 'a')
			 cout << "The largest value is -->" << max << endl;

portion no matter what input is typed. How can I fix it so it will do what is typed.


New Obstacle: How do I make the menu appear immediately after the program has responded to the input?
And additionally, how do I make it so the user needs to press enter to end the program at that point?
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

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;


int main()
{
	ifstream randomFile;

	int num = 0;
	int numbers = 0;
	int max = 1000;
	int min = 7;
	int counter = 0;
	double sum = 0.0;
	double average = 0.0;
	char choice;

	randomFile.open("random.txt");
	if (randomFile.fail())
	{
		cout << "File failed to open. \n";
		exit(1);
	}
	while (randomFile>>num)
	{
		if (num > max)
			max = num;
		if (num < min)
			min = num;

		sum = sum + num;
		counter++;
	}
	average = sum / counter;
	 do
	 {

		 cout << "Make a selction from the list: \n";
		 cout << "A.	Get the largest value \n";
		 cout << "B.	Get the smallest value \n";
		 cout << "C.	Get the sum of the values \n";
		 cout << "D.	Get the average \n";
		 cout << "E.	Get the number of value \n";
		 cout << "F.	End this program \n";
		 cout << "\n";
		 cout << "Enter your choice -->	";
		 cin >> choice;


		 if (choice == 'A' || choice == 'a')
			 cout << "The largest value is -->" << max << endl;
		 else if (choice == 'B' || choice == 'b')
			 cout << "The smallest value is -->" << min << endl;
		 else if (choice == 'C' || choice == 'c')
			 cout << "The sum of all the values is -->" << sum << endl;
		 else if (choice == 'D' || choice == 'd')
			 cout << "The average of all the numbers is -->" << average;
		 else if (choice == 'E' || choice == 'e')
			 cout << "The number of values entered is -->" << numbers++;
		 else if (choice == 'F' || choice == 'f')
			 cout << "Program ending";
		 else
			 cout << "please enter a valid choice: ";
			 cin >> choice;

	 } 
	 while (choice == 'A' || choice == 'a' || choice == 'B' || choice == 'b' || choice == 'C' || choice == 'c' || choice == 'D' || choice == 'd' || choice == 'E' || choice == 'e' || choice == 'F' || choice == 'f');

	randomFile.close();

	return 0;
Last edited on
"unresolved external" usually means the linker is looking for a function but it can't find it.

Often, this is caused by you prototyping a function, but never giving it a body.

However, in your case... it's caused by you not defining main. On line 8... your function should be main... not _main



EDIT:

also.. you are using the OR operator ( || ) all wrong.

|| will result in true if either the left or right side is nonzero.

so...

(choice == 'F' || 'f')

This will ALWAYS be true because 'f' is nonzero. You probably meant to do this:

(choice == 'F' || choice == 'f')

Although a better way would be to force choice to uppercase and only check for 'F'
Last edited on
New problem

No matter the input, the program will always do
1
2
if (choice == 'A' || 'a')
			 cout << "The largest value is -->" << max;


Last edited on
Read disch's response above. You're not using the OR (||) operator correctly. C/C++ does not support an implied left hand side of a relation.

The statement must be written as:
 
if (choice == 'A' || choice == 'a')


Oh, yeah thank you. I did that to the while part but not the body.

Now one more problem has arose which I think is my final obstacle. How can I make it so after the program responds to the input, it not only gives the answer but then also repeats the menu in the same action?
Topic archived. No new replies allowed.