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:
#include <iostream>
usingnamespace 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;
constfloat product = (first*second);
constfloat sum = (first+second);
constfloat quotient = (first/second);
constfloat 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.
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 :)