I'm a newbie at C++. I can't figure out why my program won't build. Could someone please help?

I get the error

1>LINK : error LNK2001: unresolved external symbol _mainCRTStartup
1>c:__namestuff__.exe : fatal error LNK1120: 1 unresolved externals

// File : name.cpp
// Description: Does stuff with stock
// Programmer: name
// Date: 5/23/11

#include <iostream>
using namespace std;

int main()
{
	int stock;
		cout << "Please the number of stocks sold: ";
		cin >> numberofstocks;
		cin.ignore();
		cout.setf(ios::right) << "You entered: " << numberofstocks << "\n";
		cin.get();
		cout << "Please enter a single share price: ";
		cin >> singleshareprice;
		cin.ignore();
		cout.setf(ios::right) << "You entered: " << singleshareprice << "\n";
		cin.get();

		GrossStockProceeds = numberofstocks * singleshareprice
		cout.setf(ios::right) << "The gross stock proceeds is "
			<< GrossStockProceeds << endl;
		const float COMMISSION = .06f;
		commission = GrossStockProceeds * COMMISSION
		cout.setf(ios::right) << "Commission on the gross stock proceeds using a 6% commision rate is "
			<< commission << endl;
		NetProceeds = GrossStockProceeds - commission
		cout.setf(ios::right) << "The net procceds are "
			<< NetProceeds << endl;

		return 0;
}

Recommended Answers

All 4 Replies

Member Avatar for iamthwee

Not sure. It doesn't compile though.

What IDE are you using?

I'm using Microsoft Visual Studio 2010

It's been quite a while since I did C/C++ in MSVS, but try creating a new console-type program, and it will probably provide you a stub main() of some sort, along with all the libraries it thinks you'll need. Then rename your existing main() to something else (a "normal" function), add your file into your new project, and call your new function-name from within the main() that VS gives you.

If you then want to build the same project on Linux (or whatever you might have been using with the main() you started with, if that's what you were doing), then simply provide a separate file that you compile only on linux, which includes something like:

extern int my_func();

int main()
{
  int retval = my_func();
  return retval;
}

There were quite a few errors in the code. I tried to resolve them first, but a rewrite seemed to work better and clean things up a bit. You may want to change a few items such as I described all the variables as floats. You didn't declare many of them in your attempt. Also you were missing a few semicolons at the end of statements. And not sure if .06f was intensional or a mistake fixed that as well.

// File : name.cpp
// Description: Does stuff with stock
// Programmer: name
// Date: 5/23/11

#include <iostream>
using namespace std;

int main()
{
	float stock;
	float numberofstocks;
	float singleshareprice;
	float GrossStockProceeds;
	float NetProceeds;
	float commission;
         float COMMISSION;
	cout << "enter number of stocks: ";
	cin >> numberofstocks;
	cin.clear();
	cin.ignore(1000,'\n');
	//cout << numberofstocks << endl;

	cout << "enter single share price: ";
	cin >> singleshareprice;
	cin.clear();
	cin.ignore(1000,'\n');
	//cout << singleshareprice << endl;

	GrossStockProceeds = numberofstocks * singleshareprice;
	//cout << GrossStockProceeds << endl;

	COMMISSION = .06;
	commission = GrossStockProceeds * COMMISSION;
	//cout << commission << endl;

	NetProceeds = GrossStockProceeds - commission;
	cout << NetProceeds << endl;

		return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.