954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

I have never seen this before...

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;

}
mbrinkley
Newbie Poster
16 posts since Mar 2010
Reputation Points: 10
Solved Threads: 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.

mbrinkley
Newbie Poster
16 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

What are you typing in to execute the program you've written?

jonsca
Quantitative Phrenologist
Team Colleague
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
 

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".

mbrinkley
Newbie Poster
16 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

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

caut_baia
Posting Whiz
387 posts since Apr 2010
Reputation Points: 25
Solved Threads: 49
 

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"?

mbrinkley
Newbie Poster
16 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

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.

jonsca
Quantitative Phrenologist
Team Colleague
5,621 posts since Sep 2009
Reputation Points: 1,165
Solved Threads: 581
 

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.

caut_baia
Posting Whiz
387 posts since Apr 2010
Reputation Points: 25
Solved Threads: 49
 

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;
}
mbrinkley
Newbie Poster
16 posts since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: