Not creating a .exe

I'm having a very weird problem where when I put in the following code, it doesn't show any errors but cannot pass the linking part because it's not creating a .exe file. I can comment this whole section out, paste another source code in the same file, and it will compile fine to the debugger. When I comment the other code out and try this code, it gives me the error "unable to start program C:\...\lab10.exe the system cannot find the file specified.

I have tried completely typing the program again, both in the same file and creating a new project.

Thanks.

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
#include <iostream>
#include <iomanip>
#include <Windows.h>

using namespace std;

float mph(float xxx, float yyy)
{
	return (xxx / yyy);
}

int main()
{
	cout << "How many miles have you traveled?\n";
	float fMiles = 0.0, fHours = 0.0;
	cin >> fMiles;
	while (fMiles < 0) {
		cout << "Invalid input of miles.\n";
		Sleep(1000);
		system("cls");
		cout << "How many miles have you traveled?\n";
		cin >> fMiles;
	}
	cout << "How many hours have you been traveling?\n";
	cin >> fHours;
	while (fHours <= 0) {
		cout << "Invalid input of hours.\n";
		Sleep(1000);
		system("cls");
		cout << "How many hours have you been traveling?\n";
		cin >> fHours;
	}
	cout << "\nYou were traveling at " << fixed << setprecision(2) << mph(fMiles, fHours) << " MPH";

	system("pause");
	return 0;
}
Comment out Lines 3, 19 and 28 then try to compile again and see what happens. I have a feeling you didn't tell your IDE where to find "Windows.h".
I'm sorry, that did not work. The only thing I can get to compile at this point is:
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
//#include <iostream>
//#include <iomanip>
////#include <Windows.h>

int main()
{
//	cout << "How many miles have you traveled?\n";
//	float fMiles = 0, fHours = 0;
//	cin >> fMiles;
//	while (fMiles < 0) {
//		cout << "Invalid input of miles.\n";
////		Sleep(1000);
//		system("cls");
//		cout << "How many miles have you traveled?\n";
//		cin >> fMiles;
//	}
//	cout << "How many hours have you been traveling?\n";
//	cin >> fHours;
//	while (fHours <= 0) {
//		cout << "Invalid input of hours.\n";
////		Sleep(1000);
//		system("cls");
//		cout << "How many hours have you been traveling?\n";
//		cin >> fHours;
//	}
//	cout << "\nYou were traveling at " << fixed << setprecision(2) << mph(fMiles, fHours) << " MPH";
//
//	system("pause");
	return 0;
}


When I put this in, the console will flash on the screen and go away. If I uncomment "#include < iostream>" then it gives the same error and won't compile.
Last edited on
That looks like the compiler was not installed or configured correctly. It doesn't know where to find either the include files (at compile time) or the library files (link time). You may be able to set the correct paths somewhere in the setup, or perhaps re-install the compiler.
Is that a .c or a .cpp file?
If it's .c, try renaming it to .cpp .
Or, if you're going command-line, use g++.
It is a .cpp file. If I watch the target folder, the other projects I have written put an actual .exe file there during the compiling process. With #include <iostream> commented out, this program also puts a .exe file called lab10.exe. When I uncomment #include <iostream>, it destroys lab10.exe, then just puts a random .tmp file there. This particular time it was trzEAA6.tmp.

I'm thinking it is a compiler issue, but with the same file I can put in a different code and have it pop up something else fine.
Trying to repair visual studio now.
I think you're beginning with an empty project (because you should).
If you aren't, give it a try.
Ok, I tried using windows to repair visual studio, to no avail.
I can run programs I wrote prior to the other day just fine. I am starting with an empty project. I wrote another one with just this:
1
2
3
4
5
6
7
8
9
10
#include <iostream>

using namespace std;

int main()
{
	cout << "\n"<< endl;
	system("pause");
	return 0;
}


and got the same problem, but once again this code worked:

1
2
3
4
5
6
7
8
9
10
//#include <iostream>

using namespace std;

int main()
{
//	cout << "\n"<< endl;
//	system("pause");
	return 0;
}


I think I'm just going to have to wipe and reinstall visual studio, because I cannot find anything in the tools or the preferences that will help this.
WHICH visual studio version are you using?
I'm using Visual Studio 2012 pro (student license). After updating Windows 7, repairing visual studio, and re-booting about 17 times, the problem seems to have gone away... Thank you guys for your help.
I know this thread is solved but "solutions" like this really bother me. Are you sure there isn't anything that you did: an update, a system variable change, etc, that could have fixed this?
Topic archived. No new replies allowed.