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?
#include <iostream>
#include <fstream>
#include <iomanip>
usingnamespace 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;
elseif (choice == 'B' || choice == 'b')
cout << "The smallest value is -->" << min << endl;
elseif (choice == 'C' || choice == 'c')
cout << "The sum of all the values is -->" << sum << endl;
elseif (choice == 'D' || choice == 'd')
cout << "The average of all the numbers is -->" << average;
elseif (choice == 'E' || choice == 'e')
cout << "The number of values entered is -->" << numbers++;
elseif (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;
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?