I have been given an assignment to plan, code, and execute a program to calculate data about a person. I am not here asking about how to code the program, but rather to troubleshoot at what's wrong with my compiler/command prompt. Here's what's happening: I will code a program in C++ using Crimson Editor as my text editor. With Windows XP, I use Borland Free Compiler to compile through the Command Prompt. After it compiles I execute(run) the program, but instead of printing the desired output to the command prompt screen, it opens a file with the .cpp code as the text. What is going on? I have no idea where to start and my finals programs are due by the end of the week. I am a second-semester freshman in college. All help or guidance is appreciated. Here is a sample program to use as a test:

#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;

}

I think I might have finished my code. If anybody would be interested in compiling and running it for me, that would be great too. All help is appreciated. I'm just learning the foundations of programming right now.

I'm using Borland Free Compiler so to compile I type "bcc32 mydatamtb.cpp" which is the name I have to call it for the professor. To actually execute the program afterward, where the trouble comes in, I type "mydatamtb.cpp".

You should type mydatamtb.exe because that's the executable.
I tried your code and it compiles well.

But I've never had to type ".exe" at the end of any of my program names to run them. What could have changed that would require me to type ".exe"?

You probably don't need the .exe extension, but you shouldn't use the extension .cpp? Your .cpp file is just a text file. The compiler takes that, compiles it and links it into an .exe.

Then you should type the name without the extenstion because it will look for the exe file .See the %PATHEXT% by tyiping set in the command prompt.

Ok. Wow. I am dumbfounded with myself. Like I said before, I am a beginning programmer, therefore I am going to miss PLENTY of very small yet very significant errors/inconsistencies. At the command prompt I usually type just the name of the file without the extension: ex. "mydatamtb" instead of "mydatamtb.cpp". Thank you Jonsca and caut_baia for y'alls help. I am posting the finished code for you to enjoy.

#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;
}
This article has been dead for over six months. Start a new discussion instead.