This has never happened before...

I have to plan, code, and execute a program assigned by my professor. I am not here to ask for help with the code and figuring it out, but rather I am looking for an answer as to why everytime I try to run the program, it opens as a txt file in wordpad or visual studio??? It's not doing this just for one code, but rather all of my programs. I am guessing it has to do with settings, but I'm not sure where to start. Any idea's??? All help is appreciated.
Here's a couple programs to test it with:
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
#include <iostream>
#include <string>

using namespace std;

const int DAYS_PER_YEAR = 365;
const int OUNCES_PER_POUND = 16;
const int INCHES_PER_FOOT = 12;

int main ()

{
	string name;
	int age; int heightFeet; int heightInches;
	double weight;
	
	cout << "Please enter your first name, age, weight, and height in feet and inches, each separated by a space." << endl;
	cin >> name >> age >> weight;
	cin >> heightFeet >> heightInches;
	
	cout << endl << "Age in days = " << age * DAYS_PER_YEAR << endl;
	cout << "Weight in ounces = " << weight * OUNCES_PER_POUND << endl;
	cout << "Height in inches = " << heightFeet * INCHES_PER_FOOT + heightInches << endl;
	
	return 0;

}


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
#include <iostream>

using namespace std;

float first;
float second;
char sign;

int main()
{
	cout << "Please enter the first integer." << endl;
	cin >> first;
	cout << endl;
	
	cout << "Please enter the second integer." << endl;
	cin >> second;
	cout << endl;
	
	if(second == 0)
	{
		cout << "0 cannot be the denominator." << endl;
		cout << "Please re-enter the second integer." << endl;
		cin >> second;
	}
		
	cout << "Please enter M for multiplication." << endl;
	cout << "Enter D for division." << endl;
	cout << "Enter A for addition." << endl;
	cout << "Enter S for subtraction." << endl;
	
	cin >> sign;
	
const float product = (first*second);
const float sum = (first+second);
const float quotient = (first/second);
const float difference = (first-second);
	
	if(sign == 'M' || sign == 'm')
	{
		cout << first << " * " << second << " = " << product;
	}
	if(sign == 'A' || sign == 'a')
	{
		cout << first << " + " << second << " = " << sum;
	}
	if(sign == 'S' || sign == 's')
	{
		cout << first << " - " << second << " = " << difference;
	}
	if(sign == 'D' || sign == 'd')
	{
		cout << first << " / " << second << " = " << quotient;
	}
	
	return 0;
}


The two sets of code given are NOT related in any way except that I wrote them. I have provided them merely as test programs. Here's what I do when I cross the problem:
I write the code in Crimson Editor.
I compile the .cpp file with Borland's free compiler in the command prompt on Windows XP.
Then, instead of printing to the cmd screen, it opens a txt file with the code displayed.
What do you mean by "code displayed"? And what are you opening, exactly?

Note: This is probably not a C++ problem.

-Albatross
Last edited on
Ok. I compile the program. It compiles perfectly - no errors or warnings. When I run the program, instead of printing, for example from the 2nd program, "Please enter the first integer." to the screen of the command prompt, it opens the .cpp file (which shows the literal code from the program) in either Visual Studio or WordPad.
I have been working on this program, among other programs, for the past hours. I have discovered my problem: I usually just type "name of file" without the extension ".cpp". Earlier I was typing "name of file.cpp" and it was just opening the file. I am a beginning programmer and I plan on missing more common mistakes like this lol I am posting the finished code just in case you were interested in what I was doing. Thank you for the inquiry and I hope you enjoy a beginning programmer's code :)
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <iomanip>
#include <iostream>
#include <string>

using namespace std;

//Prototypes
int ounces(float weight);
int days(int age);
int inches(int heightInches, int heightFeet);

//Main function
int main()
{
	//Variable declaration
	string name;
	string control;
	float age;
	float weight;
	float heightFeet;
	float heightInches;
	int newage;
	float newweight;
	int newheightInches;
	
		cout << "Type exit to exit the program." << endl;
		
		system("pause");
		system("cls");
		
		cout << "What is your first name?" << endl;
		cin >> name;
		
	while(name!="exit" || name!="Exit")
	{
		cout << "What is your age(in years)?" << endl;
		cin >> age;
		cout << "What is your weight(in pounds)?" << endl;
		cin >> weight;
		cout << "What is your height in feet and inches?" << endl;
		cout << "ex. 5 11" << endl;
		cin >> heightFeet >> heightInches;
//Call functions to calculate output and	
//Format output to display data
		newweight = ounces(weight);
		newage = days(age);
		newheightInches = inches(heightInches, heightFeet);
		
		cout << setw(30) << left << setfill('=') << '=' << endl;
		cout << name << " You are " << newage;
		cout << " days old." << endl;
		cout << "You weigh " << newweight;
		cout << " ounces." << endl;
		cout << "You are " << newheightInches;
		cout << " inches tall."<< endl;
		cout << setw(30) << left << setfill('=') << '=' << endl;
		cout << setw(30) << left << setfill('=') << '=' << endl;
		
		cout << "Type exit to exit the program." << endl;
		
		system("pause");
		system("cls");
		
		cout << "What is your first name?" << endl;
		cin >> name;
							
	if(name=="Exit" || name=="exit")
		{
			cout << "Thank You!";
			exit(1);
		}
	}
	return 0;
}

int ounces(float weight)
{
	float newweight;
	const int OUNCES_PER_POUND = 16;
	newweight = (weight * OUNCES_PER_POUND);
	return newweight;
}


int days(int age)
{
	int newage;
	const int DAYS_PER_YEAR = 365;
	newage = (age * DAYS_PER_YEAR);
	return newage;
}

int inches(int heightInches,int heightFeet)
{
	int newheightInches;
	const int INCHES_PER_FOOT = 12;
	newheightInches = ((heightFeet * INCHES_PER_FOOT) + heightInches);
	return newheightInches;
}
Make sure you are clicking on the exe file and not the cpp file.

VS will put your executable in a subdirectory named something like "Release" or "Debug".
Topic archived. No new replies allowed.