I am taking an introductory C++ course and am attempting to complete the first assignment. The task is to type up a bit of code given as a printout and then run it testing various inputs. I have typed up the code but I'm getting the error messages listed below on Visual Studio Express 2013. I have tried running the code on two different web compilers and it seemed to work fine.
The errors are...
1) error LNK2019: unresolved external symbol_main referenced in function__tmainCRTStartup
2) error LNK1120: 1 unresolved externals
I have done a bit of googling and I have asked in the #learnprogramming IRC without much luck. Does anyone here know what the issue might be? I've pasted the code I'm attempting to run below.
//****************************************
// Today's temp program
// this program reads in the temperature in degrees Fahrenheit
// and converts it to Celsius and Kelvin. It expects a valid
// integer or floating point number as the input.
#include <iostream>
usingnamespace std;
constdouble FAHR_2_CEL_BASE_ADJ = 32.0; // Dif at frezing point
constdouble FAHR_2_CEL_FACTOR = 5.0 / 9.0;// Ratio for conversion
constdouble CEL_2_KEL = 273.15; // Diff for celsius to Kelvin
int main()
{
double input_temp; // Holds the input value
double celsius_temp; // Holds the celsius result
cout << "Please enter the temperature in Fahrenheit degrees: ";
cin >> input_temp;
// Now calculate the temp in Celsius
celsius_temp = (input_temp - FAHR_2_CEL_BASE_ADJ) *
FAHR_2_CEL_FACTOR;
cout << "A temperature of " << input_temp << " degrees ";
cout << "Fahrenheit converts to " << celsius_temp;
cout << " degrees Celsius. \nIn degrees Kelvin it is ";
cout << celsius_temp + CEL_2_KEL << ".\n\nThank you for using "
<< "this delightful program which was \nkeyed into the "
<< "computer by Tieria." << endl << endl;
return 0;
}
@Yanson, hmm perhaps I didn't create the right type of project or something... would you you mind listing off the menus you went though in order when you created a new project? I've never used Visual Studio before and there seemed to be a lot of options/steps required to get setup.
Click new project
on left pain click Visual C++
Click Empty Project
Give the project a name
click ok
in the solution explorer Right click Source Files select add/new Item
Click C++ File(.cpp)
Give the file a name and click add
The code seems work perfect for GNU C++ Compiler to compile.
I wonder why you don't try some free and popular compilers after Visual Studio 2013 Express Compiler isn't working for your code.
@Yanson That seems to have solved my problem. I'm not sure what I did the first time around but thank you very much! ^_^
Any idea how to keep the console window open. The instruction packet I'm following says to:
Right click on the project name.
Select Properties
Configuration Properties
>Linker
>>System
select drop down for subSystem
select Console (/SUBSYSTEM;CONSOLE)
I have done this but the console still insta closes after I enter my temperature number. Right now I'm getting it to work by adding in an extra cin >> statement at the end, but I know that isn't how it's supposed to be done.
I'm using Visual Studio because I have no experience using anything else and it was what we had on the university computers in class. This is the first programming course I have taken. The professor stated that we were free to use a different compiler if we wanted and that next week he would be showing us how to get setup in a Linux environment. Apparently Visual Studio is just used for the first week because it's the default on all of the Win8 lab/library computers.
There are lots of ways to keep the console window open. If you look at the top of the beginners forum there is a thread about it. http://www.cplusplus.com/forum/beginner/1988/
I usually add some cin.ignore() statements
//****************************************
// Today's temp program
// this program reads in the temperature in degrees Fahrenheit
// and converts it to Celsius and Kelvin. It expects a valid
// integer or floating point number as the input.
#include <iostream>
usingnamespace std;
constdouble FAHR_2_CEL_BASE_ADJ = 32.0; // Dif at frezing point
constdouble FAHR_2_CEL_FACTOR = 5.0 / 9.0;// Ratio for conversion
constdouble CEL_2_KEL = 273.15; // Diff for celsius to Kelvin
int main()
{
double input_temp; // Holds the input value
double celsius_temp; // Holds the celsius result
cout << "Please enter the temperature in Fahrenheit degrees: ";
cin >> input_temp;
cin.ignore();//-----------------------------------------------------new
// Now calculate the temp in Celsius
celsius_temp = (input_temp - FAHR_2_CEL_BASE_ADJ) *
FAHR_2_CEL_FACTOR;
cout << "A temperature of " << input_temp << " degrees ";
cout << "Fahrenheit converts to " << celsius_temp;
cout << " degrees Celsius. \nIn degrees Kelvin it is ";
cout << celsius_temp + CEL_2_KEL << ".\n\nThank you for using "
<< "this delightful program which was \nkeyed into the "
<< "computer by Tieria." << endl << endl;
cin.ignore();//-----------------------------------------------------new
return 0;
}
@Yanson That looks very helpful, thanks! What is the point of adding cin.ignore() statements and why do you need two of them here? I tried adding only the one at the end and the console window still closed.
After the user enters a number they press enter. Pressing enter generates a newline character '\n' so the input looks like this 100'\n' . The first cin >> input_temp; extracts the 100 from the input stream, but the newline is still there waiting to be input. the first cin.ignore(); ignores the newline character. The second cin.ignore(); keeps the console window open